Write a Ruby program to split a delimited string into an array.
color = "Red, Green, Blue, White" nums = "1, 3, 4, 5, 7" print "Original delimited string:\n" print color,", " print nums print "\nString to array:\n" color_array = color.split(",") nums_array = nums.split(",").map { |s| s.to_i } print color_array print "\n",nums_array
Output:
Original delimited string: Red, Green, Blue, White1, 3, 4, 5, 7String to array: ["Red", " Green", " Blue", " White"] [1, 3, 4, 5, 7]
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer