RE: multiple componentsSeparatedByString
RE: multiple componentsSeparatedByString
- Subject: RE: multiple componentsSeparatedByString
- From: Koen van der Drift <email@hidden>
- Date: Sat, 23 Nov 2002 12:34:03 -0500
>
2. Use an NSScanner, which can look for sets of characters. You can define
>
your own set of characters to scan for. Scanner code is quite ugly and
>
verbose compared to componentsSeparatedByString:, but it gets the job done.
>
I am trying this now, but run in some problems. Here's a snippet:
NSMutableArray *anArray;
NSScanner *scanner;
NSCharacterSet *stopSet;
NSString *result;
anArray = [[NSMutableArray alloc] init];
scanner = [NSScanner scannerWithString:s];
stopSet = [NSCharacterSet characterSetWithCharactersInString:@"ABC];
while (! [scanner isAtEnd])
{
if ([scanner scanCharactersFromSet:stopSet intoString:&result])
{
[anArray addObject:result];
}
}
So what I want to do is scan the string s, and everytime either the
character 'A' or 'B' or 'C' is found take the part of s (including either A
or B or C), and store it in result.
So if the input is: QWERTYASDFGZXCVBNM
I would like to get the following strings in anArray:
QWERTYA
SDFGZXC
VB
NM
However, the code above just stays in an infinite loop. If I use
[scanner scanUpToCharactersFromSet:stopSet intoString:&result], I only get
the first string, minus the 'A', and then the loop is infinite again.
How can I fix this?
thanks,
- Koen.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.