in reply to How do I quickly strip blank space from the beginning/end of a string?
-
All of your solutions require the last non-space character to be an uppercase letter. You could say you're investigating a subset of the original question, except that your input has no uppercase letters. Use \s or a space instead of [^A-Z]. Use \S instead of [A-Z].
-
Some of your solutions have problems with trailing newlines due to the missing "s" modifier. /./ doesn't match newlines without it.
-
All but the last of your solutions don't work if the input is made entirely of spaces.
There's also a issue with your benchmark. Benchmarking code that removes trailing spaces when your input never has trailing spaces is odd. Include a case where the input has trailing spaces!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How do I quickly strip blank space from the beginning/end of a string?
by blahblahblah (Priest) on Jul 21, 2009 at 22:25 UTC | |
by ikegami (Patriarch) on Jul 21, 2009 at 23:06 UTC | |
by blahblahblah (Priest) on Jul 22, 2009 at 01:12 UTC | |
by ikegami (Patriarch) on Jul 22, 2009 at 04:22 UTC |