There is a substring that occurs in a string several times. I use rangeOfString
, but it seems that it can only find the first location. How can I find all the locations of the substring?
NSString *subString1 = @"</content>";
NSString *subString2 = @"--
";
NSRange range1 = [newresults rangeOfString:subString1];
NSRange range2 = [newresults rangeOfString:subString2];
int location1 = range1.location;
int location2 = range2.location;
NSLog(@"%i",location1);
NSLog(@"%i",location2);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…