Ruby function to remove all white spaces?

What is the Ruby function to remove all white space? Kind of like php's trim() ?


如果你只想删除前后的空格(比如PHP的修剪),你可以使用.strip ,但是如果你想删除所有的空格,你可以使用.gsub(/s+/, "")


s = "I have white space".delete(' ')

并模仿PHP的trim()函数:

s = "   I have leading and trailing white space   ".strip

Related answer:

"   clean up my edges    ".strip

returns

"clean up my edges"
链接地址: http://www.djcxy.com/p/44840.html

上一篇: 为什么我们要在Ruby的类中放一个模块?

下一篇: Ruby函数删除所有空格?