ruby - Splitting array and get desired elements -
If I have this array:
How can I get this array from it? It should also work ... ["1", "2", "3, one", "4, b"]
["1", "2", "3", "4"]
Array = ["1", "2", "3, a", "4, b"] i in 0 .. array.length () - 1 if array [i] .include? (",") Ab = array [i] .split (",") array [i] = ab [0] end-end print array # ["1", "2", "3", "4"] < / Code>
Comments
Post a Comment