ios - Split array object "1;item1" into 1 and item1 -
country = ( "3;india", "4;us", "5;uk", ) state = ( "9;3;uttar pradesh", "10;3;maharashtra", "11;3;andaman , nicobar islands" ) city = ( "110;3;10;pune", "111;3;10;mumbai", "112;3;10;nasik", )
i want show country name in dropdown
list , want pass it's id web service. if user selects india, have pass 3. how can this?
as understand have array strings in it.
if so, need split strings.
objective-c code
nsarray *country = @[@"3;india", @"4;us", @"5;uk"]; nsstring *countrystr = country[0]; // 3; india nsarray *countryarr = [countrystr componentsseparatedbystring:@";"]; nsstring *countrycode = countryarr.firstobject; //3 nsstring *countryname = countryarr.lastobject; //india nslog(@"%@", countrycode); //3 nslog(@"%@", countryname); //india
swift code
let country : nsarray = ["3;india", "4;us", "5;uk"] let countrystr = country[0] let countryarr : nsarray = countrystr.componentsseparatedbystring(";") let countrycode = countryarr.firstobject let countryname = countryarr.lastobject if let countrycodepr = countrycode { print(countrycodepr) } if let countrynamepr = countryname { print(countrynamepr) }
Comments
Post a Comment