问题描述:

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.

网友答案:

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
网友答案:
string.squish! 

This might modify the string itself. Also, any empty string like " ".blank? will return true.

相关阅读:
Top