ios - How to separate NSString with multiple commas? -
am having nsstring
nsstring * countrystr = @"6023117,159,en_us,seychelles,sc,seychelles,6023185,95,en_us,kuwait,kw,kuwait,6023182,172,en_us,swaziland,sz,swaziland,6023185,157,en_us,saudi arabia,sa,saudi arabia,6023182,177,en_us,tanzania,tz,tanzania,6023185,179,en_us,togo,tg,togo,6023185,87,en_us,cote d'ivoire,ci,cote d'ivoire";
now want display countries suffixed "en_us". can tell me how split string countries.
i did this
nserror * error; nsstring* imagename = [[nsbundle mainbundle] pathforresource:@"countrylist" oftype:@"txt"]; nsstring * countrstr = [nsstring stringwithcontentsoffile:imagename encoding:nsstringencodingconversionallowlossy error:&error]; nsarray * dfd = [countrstr componentsseparatedbystring:@"en_us"]; for(int i=0;i<dfd.count;i++) { nsstring * nama = [dfd objectatindex:1]; nsarray * djk = [nama componentsseparatedbystring:@","]; nsstring * aksjd = [djk objectatindex:1]; }
you can this;
nsstring * countrystr = @"6023117,159,en_us,seychelles,sc,seychelles,6023185,95,en_us,kuwait,kw,kuwait,6023182,172,en_us,swaziland,sz,swaziland,6023185,157,en_us,saudi arabia,sa,saudi arabia,6023182,177,en_us,tanzania,tz,tanzania,6023185,179,en_us,togo,tg,togo,6023185,87,en_us,cote d'ivoire,ci,cote d'ivoire"; nsarray * arrdata = [countrystr componentsseparatedbystring:@","];;//[countrystr componentsseparatedbystring:@"en_us"]; for(int i=0;i<arrdata.count;i++) { nsstring * str = [arrdata objectatindex:i]; if ([str isequaltostring:@"en_us"] && i<arrdata.count-1) { nsstring* countryname = [arrdata objectatindex:i+1]; nslog(@"countryname %@", countryname); } }
but should manage info in file, loading resource.
ios nsstring
No comments:
Post a Comment