Rails Strip方法无法正常工作

时间:2014-01-31 19:37:49

标签: ruby-on-rails strip gsub

所以,如果有人遇到同一个问题,我有一个字符串:

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

有趣的是,在尝试a.strip时,我的字符串没有更改为:

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

1 个答案:

答案 0 :(得分:4)

这里的问题是,我有 或其他一些空间阻止strip做最好的事情。

我的解决方案,首先用空格替换所有空格:

a.gsub("\u00A0", " ")(我最初尝试a.gsub(" ", " "),但没有运气)

多田!

现在我得到了预期的a.strip结果:)

(也许有更明确的方法可以做到这一点,如果是这样,请告诉我)