CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 1999
    Posts
    47

    Perl function for TrimRight

    Is there a function in Perl equivalent to TrimRight. I need to trim the trailing chars '0' from a string.

    Can you help me?


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Perl function for TrimRight

    might require Perl 5:

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


  3. #3
    Join Date
    Jun 1999
    Posts
    47

    Re: Perl function for TrimRight

    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 ...





  4. #4
    Join Date
    May 1999
    Posts
    3,332

    Re: Perl function for TrimRight

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


  5. #5
    Join Date
    Jun 1999
    Posts
    47

    Re: Perl function for TrimRight

    You-ve been great !
    Thank you !
    I gave you 3 grades.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured