Ruby: Split string at character, counting from the right side

后端 未结 6 1431
小蘑菇
小蘑菇 2020-12-10 00:59

Short version -- How do I do Python rsplit() in ruby?

Longer version -- If I want to split a string into two parts (name, suffix) at the first \'.\' character, this

6条回答
  •  半阙折子戏
    2020-12-10 01:26

    if this="what.to.do" you can do this:

    this.split(%r{(.+)\.})
    

    and you'll get back

    ["", "what.to", "do"]
    

提交回复
热议问题