Reputation: 2400
If i have this array:
array = ["1\r\ndate\r\ntext\"...", "2\r\ndate\r\ntext", "3\r\ndate\r\ntext_one\r\ntext_two."]
And I want to split in:
array = [[1, date, "text"],[2, date, "text"], [3, date, "text", "text"]]
You know...dividing that strings into array. How can I do that?
Upvotes: 0
Views: 104
Reputation: 38728
You can just map over the array and split the substrings
result = array.map { |input| input.split }
As @davenewton mentions this can be simplified to the following
array.map(&:split)
If the delimiters of the substring change then you can pass the new delimeter as an argument to split
for example if you used :
result = array.map { |input| input.split(':') }
Upvotes: 1