我想从字符串的末尾重复删除一个特定的字符,只留下一个唯一的字符。
所以我希望以下情况发生:
buns = "well, that was unusual....."
buns.dedupe(".")
#=> "well, that was unusual."
提前致谢!
答案 0 :(得分:1)
如果您只想从字符串末尾删除重复字符(而不是字符串中的任何位置,如String#squeeze
那样):
"well, that was unusual.....".gsub(/\.+$/, '.')