Skip navigation.
 
mlRe: multiple componentsSeparatedByString
FROM : Koen van der Drift
DATE : Mon Nov 25 02:37:16 2002

At 6:04 PM -0500 11/24/02, Jonathan Jackel wrote:

>Scanners are a bit weird.  You need to "scanUpTo" to scan past the undesired
>part of the string, and then scan the characters.  I think this will work.
>
>
>  while (! [scanner isAtEnd])
>  {
>      if ([scanner scanUpToCharactersFromSet: stopSet intoString:nil] &&
>            [scanner scanCharactersFromSet:stopSet intoString:&result])
>      {
>          [anArray addObject:result];
>      }
>  }


Thanks Jonathan. Unfortunately, this doesn't work. Starting with the string
"QWERTYASDFGZXCVBNM" I get three single charcters as result: "A" "C" and
"B", instead of "QWERTYA", "SDFGZXC", "VB" and "NM".

>>  stopSet = [NSCharacterSet characterSetWithCharactersInString:@"ABC];
>
>You need a closing quote mark after the string.


Yes, I noticed that after posting, it was a copy-paste error.


I realized later that besides the result strings, I also need the position
of the result string in the original string. I didn't see any methods in
NSScanner that allowed me to get that data, although I might be able to do
it with NSString's rangeOfString or maybe rangeOfCharacterFromSet.
Moreover, in some occasions I need to skip one of the characters in the
stopSet. So I guess scanning the string character by character is the way
to go. Unless I am missing something very essential ;)

Are there any examples/tutorials of NSString parsing available?

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