I have a string
\"1,2,3,4\"
and I\'d like to convert it into an array:
[1,2,3,4]
How?
String Integer without space as Stringarr = "12345"
arr.split('')
output: ["1","2","3","4","5"]
String Integer with space as Stringarr = "1 2 3 4 5"
arr.split(' ')
output: ["1","2","3","4","5"]
String Integer without space as Integerarr = "12345"
arr.split('').map(&:to_i)
output: [1,2,3,4,5]
arr = "abc"
arr.split('')
output: ["a","b","c"]
Explanation:
arr -> string which you're going to perform any action.split() -> is an method, which split the input and store it as array.'' or ' ' or ',' -> is an value, which is needed to be removed from given string.