Re: multiple componentsSeparatedByString
Re: multiple componentsSeparatedByString
- Subject: Re: multiple componentsSeparatedByString
- From: Koen van der Drift <email@hidden>
- Date: Sun, 24 Nov 2002 20:37:16 -0500
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@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.