ruby - Splitting array and get desired elements -


If I have this array:

["1", "2", "3, one", "4, b"]

How can I get this array from it?

  ["1", "2", "3", "4"]    

It should also work ...

  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

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

jsp - Google line chart x-axis shrinks on transition -

java - Reaching JTextField in a DocumentListener -