How to split a string in Ruby and get all items except the first one?

前端 未结 9 1935
日久生厌
日久生厌 2021-01-31 06:47

String is ex=\"test1, test2, test3, test4, test5\"

when I use

ex.split(\",\").first

it returns

\"test1\"
         


        
9条回答
  •  不要未来只要你来
    2021-01-31 07:20

    You can also do this:

    String is ex="test1, test2, test3, test4, test5"
    array = ex.split(/,/)
    array.size.times do |i|
      p array[i]
    end 
    

提交回复
热议问题