I've been tasked with another "fix" which seems simple but isn't (to me). I need to remove all leading 0s of a string:
"00000002035"
needs to be
" 2035"
Is there some function I can use to do this already? The spacing needs to remain the same though.
Last edited by NeedHelp; 03-29-2007 at 09:33 AM. Reason: Forgot to mention
you should be able to use regex
I found this:
Perl Reference
which lead me to making this:
And does what I need. Is this the best method though?Code:$mystring =~ s/^0*//; $mystring = sprintf("%- 18s", $mystring);
I don't know anything about perl so I cant tell you if thats the BEST way to do it. From my little understanding of regular expressions, it 'looks good.'
My theory is, if it works leave it alone![]()
Thanks for the input. This method seems to be working fine for now.
some other ways:
Code:$new = sprintf "%d" , "000023"; print $new;Code:$val = "00032"; $new = int $val; print $new;
I never thought of the int $val method. That would work fine I would think.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks