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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -