新手问题 怎样删除字符串当中的特定字符

easonlovejiven · February 04, 2015 · Last by hmilym replied at February 07, 2015 · 5238 hits

怎样删除字符串当中的特定字符

str = "sabcdaaaa"
str.delete! 'a'
puts str
str.gsub!(/a/, "")

不对啊,,朋友

@easonlovejiven ,

ree-1.8.7-2011.12 :005 > str.gsub!(/a/, "")
 => nil
ree-1.8.7-2011.12 :006 > str
 => "sbcd"

没有不对,gsub! 会改变 str 的值

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