Spl*_*lin 4 ruby ruby-on-rails
我有人输入一个带有字符串输入的表单.我需要做的是用"AND"(没有引号)替换字符串中的任何空格.最好的方法是什么?
另外,如果我想删除字符串中的所有空格,我将如何执行此操作?
谢谢
Pet*_*ter 12
替换为和:
s = 'this has some whitespace'
s.gsub! /\s+/, ' AND '
=> "this AND has AND some AND whitespace"
Run Code Online (Sandbox Code Playgroud)
完全删除:
s = 'this has some whitespace'
s.gsub! /\s+/, ''
=> "thishassomewhitespace"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6609 次 |
| 最近记录: |