Click to See Complete Forum and Search --> : Perl function for TrimRight


Daniel Zilcsak
June 30th, 1999, 08:17 AM
Is there a function in Perl equivalent to TrimRight. I need to trim the trailing chars '0' from a string.

Can you help me?

Lothar Haensler
June 30th, 1999, 09:43 AM
might require Perl 5:

$_= "the string000";
s/(.*?)0*$/$1/gi;
print($_);

Daniel Zilcsak
June 30th, 1999, 10:09 AM
Thanks !
It was veri helpfull !

But I wolu like to ask you something more.

I have a value, for exemple:

$_ = "1234.0000";
#i execute your code
s/(.*?)0*$/$1/gi;
and the string is "1234."

How can I also remove the trailing "." ?

I would be very gratefull to you if you could help me out ...

Lothar Haensler
June 30th, 1999, 10:10 AM
$_= "1234.000";
s/(.*?)\.?0*$/$1/gi;
print($_);

Daniel Zilcsak
June 30th, 1999, 10:29 AM
You-ve been great !
Thank you !
I gave you 3 grades.