Get substring after the first = symbol in Ruby

后端 未结 5 1906
盖世英雄少女心
盖世英雄少女心 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:31

    split(char) is another function which can be used. For instance, we want to get substring before char ':' from "answer:computer" then, we can use "answer:computer".split(':')[0].So, we would get result as "answer".

提交回复
热议问题