How to split string into only two parts with a given character in Ruby?

前端 未结 4 1819
生来不讨喜
生来不讨喜 2020-12-29 19:42

Our application is mining names from people using Twitter to login.

Twitter is providing full names in a single string.

Examples

1. \"Froeder         


        
4条回答
  •  清歌不尽
    2020-12-29 20:00

    The second argument of .split() specifies how many splits to do:

    'one two three four five'.split(' ', 2)
    

    And the output:

    >> ruby -e "print 'one two three four five'.split(' ', 2)"
    >> ["one", "two three four five"]
    

提交回复
热议问题