Reputation: 688
I'm trying to use the squish method to reduce multiple white spaces in a string to single white spaces. However, I have a string with mutliple spaces which are not reduced. When I check for string[space_position].blank?
it returns true, but its neither empty, nor does is it == ' '
.
What could cause this behavior?
Not sure if this is relevant, but the string comes from a mongoDB and was saved there by Locomotive CMS.
Upvotes: 2
Views: 366
Reputation: 67850
the three spaces: [32,160,32]
ASCII 160 is a non breaking space usually found in HTML, and apparently not recognized as squish
as a space. Try to replace it before:
string.gsub(160.chr, ' ').squish
Upvotes: 2
Reputation: 685
string.squish!
This might modify the string itself. Also, any empty string like " ".blank? will return true.
Upvotes: 0