Question

So just in case someone stumbles across the same issue, I have a string:

a = " I am a string with whitespace at the start and end "

Interestingly when trying to a.strip, my string didn't change to:

a = "I am a string with whitespace at the start and end"

Was it helpful?

Solution

The issue here was, that I had   or some other kind of space which prevented strip from doing what it does best.

My solution, first replace all my spaces with spaces:

a.gsub("\u00A0", " ") (I tried a.gsub(" ", " ") at first, but no luck)

tada!

Now I got my expected a.strip result :)

(Maybe there is a clearer way to do this, if so let me know)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top