in reply to Re^3: How do I quickly strip blank space from the beginning/end of a string?
in thread How do I quickly strip blank space from the beginning/end of a string?
Good point. I've tried the 3 methods below:
andif ($x =~ /\s/)
andif (substr($x, -1) =~ /^\s/
The rindex method is much faster on the data that has spaces; otherwise the substr method is the fastest. Any other good ideas, keeping in mind that the data (I think) won't often contain any trailing spaces?if (rindex($x," ") == 0 || rindex($x,"\r") == 0 || rindex($x,"\n") == + 0 || rindex($x,"\t") == 0)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: How do I quickly strip blank space from the beginning/end of a string?
by ikegami (Patriarch) on Jul 22, 2009 at 04:22 UTC |
In Section
Seekers of Perl Wisdom