删除字符串中的第一个“#”字符 - Rails

时间:2013-05-17 19:02:36

标签: ruby-on-rails ruby

如何删除第一个"#"字符串的字符?

实施例

"fooo#oooooo#bar"

预期结果:

"fooooooooo#bar"

"fooo#oooooo#bar".delete_first("#") // Exist some method like this?

1 个答案:

答案 0 :(得分:21)

sub(不是gsub)会这样做:

"fooo#oooooo#bar".sub('#', '') #=> "fooooooooo#bar"