新手问题 ruby 字符串处理

xiaoxiao · June 17, 2013 · Last by xiaoxiao replied at June 17, 2013 · 4014 hits

我有一个字符串“hello world”用 ruby 的什么命令得到字符 hello world 就是去掉头尾的“

'"hello world"'.gsub /(^\"|\"$)/, ''

%{"hello world"}.gsub /"([^"]+)"/, '\1'

LS 的几位给出了答复 但还是 小建议一下“是针对位置还是针对特殊字符的去除呢”

主要是去掉两侧的引号""

"hello world".each_char {|c| print c, ''}

a = "hello world" a[1..a.length-2]

#6 楼 @karmue 你没实验过吧...

倒 丢人了 我以为是 a =""hello world""

thx,各位的热心回答

You need to Sign in before reply, if you don't have an account, please Sign up first.