i want find index of 8th occurrence of " " split string there. can find line of code gives me array of occurrences of " ". there function can call give me information?
int numberofoccurences = [[myliststring componentsseparatedbystring:@" "] count]; edit 1: far solution came with:
if(numberofoccurences > 8) { //find index of place want split picking //arbitrary number , finding first white space int index = (int)[[myliststring substringfromindex:45] rangeofstring:@" "].location; nslog(@"index: %i", index); //make substring nsstring *substringlist1 = [myliststring substringtoindex:(45+index)]; nsstring *substringlist2 = [myliststring substringfromindex:(45+index)]; }
there no method find 8th space, there building blocks need.
the nsstring method rangeofstring:options:range: find first occurrence of first argument within range specified third argument, returns range match. start third argument being whole string , iterate reducing range search using previous result.
if looking white space , not space might consider similar rangeofcharactersfromset methods.
if don't want eighth space, trying break string @ given length, can @ componentsseparatedbystring/componentsseparatedbycharactersinset , reassemble resultant “words" strings of appropriate length. might want @ nsscanner.
hth
Comments
Post a Comment