Get substring after the first = symbol in Ruby

后端 未结 5 1685
盖世英雄少女心
盖世英雄少女心 2021-02-02 05:48

Purely out of curiosity, is there a more elegant way to simply get the substring after the first = symbol in a string? The following works to give back name=b

5条回答
  •  执笔经年
    2021-02-02 06:40

    There's also this way:

    string.partition('=')[2]
    

    And this one:

    string.sub(/.*?=/, '')
    

    I think I prefer the regexp way you mentioned, though.

提交回复
热议问题