Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rex-gurus: Replace first character in a string 1

Status
Not open for further replies.

thendal

Programmer
Aug 23, 2000
284
Hi all!

I have replace first character in a string with null ie)

S344545 to 344545 ...

i tried some thing like this

$t=M23443;
@m=split(//,$t);
shift(@m);
$s=join('',@m);
print "$s";

i knew there is better one liner ...

Thank you.
 
if you mean "delete the 1st character in the string", use s/something/something_else/
 
While you can do this with an re, it's overkill.
Check out the substr() function and the length() function.
(You can do it with substr() alone, but I think the first
solution that will occur to many involves both.)
 
mikevh is absolutely correct, or better put, I agree with his suggested solution 100%.

Code:
$a = "abcde";
$b = substr($a, 1);
print $b;  # gives 'bcde'

--jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top