in reply to obtaining the three leftmost characters of a string
If you're sure that - or some other delimeter will always be present and in the same position, split would suit your example...
# left = 555, right = 4587 my($left,$right) = split( /-/ => $string, 2 );
If you really wanted only the first three regardless of content, then take a look at substr...
# left = 555, string = 555-4587 my($left) = substr( $string => 0, 3 ); # leftmost = 555, string = -4587 my($left) = substr( $string => 0, 3, "" );
--k.
|
---|
Replies are listed 'Best First'. | |
---|---|
•Fat Arrow abuse (was Re: Re: obtaining the three leftmost characters of a string)
by merlyn (Sage) on Jun 10, 2002 at 14:33 UTC |