[英]Remove all space characters from string in Rails
How do I remove all spaces and white-space characters from a string? 如何从字符串中删除所有空格和空格字符?
I have tried the following: 我尝试了以下方法:
number = params[:phone][:number]
number.delete(' ').gsub(/\D/)
However, if I enter a number with a space I still get something like 0000 000
. 但是,如果输入带空格的数字,我仍然会得到类似
0000 000
。 It's supposed to return 0000000
, ie, no spaces. 应该返回
0000000
,即没有空格。
Use the destructive delete method. 使用破坏性删除方法。 #delete!
#删除!
number.delete!(' ').gsub(/\D/)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.