Ruby/String/Convert to Array

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

From a String to an Array

split converts a string to an array. 
puts "0123456789".split



regular expression matches a comma and a space (/, /)

c_w = "George Jones, Conway Twitty, Lefty Frizzell, Ferlin Husky"
puts c_w.split(/, /)



splitting up all the individual values and converting them into elements

puts "0123456789".split( // ) # => ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]