Re: Perl Regex to strip all but last character in a string
by "Jan Morell" <jan_man(at)bellsouth.net>
|
Date: |
Thu, 1 Mar 2001 18:23:25 -0500 |
To: |
"Tom Grenier" <tom(at)sqlman.com> |
Cc: |
<hwg-languages(at)hwg.org> |
References: |
co janman2 sqlman |
|
todo: View
Thread,
Original
|
|
Thanks Tom,
I had put together a rather clunky if else statement to get the job done,
but your solution is much better.
Jan
Tom Grenier Wrote:
If the last char of the string is always a digit, how about:
$foo = substr($foo, length($foo) -1);
Jan Morell wrote:
> Hi List Members,
>
> I am trying to strip all but the last digit in a string. I tried using:
> $foo =~ s!^..!!;
> which workd fine if there are 3 digits in the string. (The case most of
the
> time), but there might only be 2 digits.
>
> Am I going about this backwards?
>
> Thanks for any help.
>
> Jan
HWG: hwg-languages mailing list archives,
maintained by Webmasters @ IWA