Skip navigation.
 
mlRE: multiple componentsSeparatedByString
FROM : Koen van der Drift
DATE : Sat Nov 23 18:34:03 2002

>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_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlmultiple componentsSeparatedByString Koen van der Drift Nov 22, 15:06
mlRE: multiple componentsSeparatedByString Jonathan E. Jackel Nov 22, 17:04
mlRE: multiple componentsSeparatedByString Koen van der Drift Nov 22, 17:18
mlRE: multiple componentsSeparatedByString Koen van der Drift Nov 23, 18:34
mlRE: multiple componentsSeparatedByString Koen van der Drift Nov 24, 01:12
mlRe: multiple componentsSeparatedByString Jonathan Jackel Nov 25, 00:04
mlRe: multiple componentsSeparatedByString Koen van der Drift Nov 25, 02:37
mlRe: multiple componentsSeparatedByString Koen van der Drift Nov 25, 03:03
mlRe: multiple componentsSeparatedByString Jonathan Jackel Nov 25, 04:12
mlRe: multiple componentsSeparatedByString Koen van der Drift Nov 25, 14:54
mlNSScanner (was Re: multiple componentsSeparatedByString) Koen van der Drift Nov 29, 20:02
mlRe: NSScanner (was Re: multiple componentsSeparatedByString) Jonathan Jackel Nov 30, 04:06