Reputation: 395
On Mac OS X, in Ojective-C, I wanted to know if anyone could give me some pointers as to how I could parse strings contained between "x" and "y".
My current code only enables me to separate the strings separated by one componennt :
NSArray * allLines = [theDataObject componentsSeparatedByString:@"word-1"];
Ideally, I would like to isolate the strings contained between @"word-1" and @"word-2".
Could anyone help please? Thanks in advance!
Upvotes: 1
Views: 353
Reputation: 16861
Check the documentation for NSScanner
. The methods you want are -scanUpToString:intoString:
and -scanString:intoString:
Upvotes: 1
Reputation: 6991
NSString *str = [theDataObject stringByReplacingOccurencesOfString:@"word-2" withString:@"word-1"];
NSArray *allLines = [str componetnsSeperatedByString:@"word-1"];
You don't care whether its word-1 or word-2 as those do not come back in the array anyways.
Upvotes: 1