Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split a string into an array of numbers

My string:

>> pp params[:value]
"07016,07023,07027,07033,07036,07060,07062,07063,07065,07066,07076,07081,07083,07088,07090,07092,07201,07202,07203,07204,07205,07206,07208,07901,07922,07974,08812,07061,07091,07207,07902"

How can this become an array of separate numbers like :

["07016", "07023", "07033" ... ]
like image 706
Trip Avatar asked Apr 01 '11 12:04

Trip


2 Answers

result = params[:value].split(/,/)

String#split is what you need

like image 68
Matt Greer Avatar answered Nov 16 '22 02:11

Matt Greer


Try this:

arr = "07016,07023,07027".split(",")
like image 37
Jonas Elfström Avatar answered Nov 16 '22 01:11

Jonas Elfström