From: Christopher Swasey Date: 2008-03-03T14:42:25+09:00 Subject: Re: Split the string On 3/3/08, Sijo Kg wrote: > I have a string > @selected_related_model_id_assotype_and_name=params[:relatedidmodelasso] > > This is of the form > 3:43;SD,2:65;SD,3:50;Inc > > How can i split this to get > > =>[["3","43","SD"],["2","65","SD"],["3","50","Inc"]] > > Sijo First split by the comma, then #map the result and split using a conditional: "3:43;SD,2:65;SD,3:50;Inc".split(/,/).map { |i| i.split(/:|;/) } => [["3", "43", "SD"], ["2", "65", "SD"], ["3", "50", "Inc"]] Christopher