Re: multiple componentsSeparatedByString
Re: multiple componentsSeparatedByString
- Subject: Re: multiple componentsSeparatedByString
- From: Jonathan Jackel <email@hidden>
- Date: Sun, 24 Nov 2002 18:04:43 -0500
>
I am trying this now, but run in some problems. Here's a snippet:
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];
}
}
Also, your e-mail has this code:
>
stopSet = [NSCharacterSet characterSetWithCharactersInString:@"ABC];
You need a closing quote mark after the string.
>
I found another solution. Instead of using an NSScanner, I just extract
>
each character from the string and test it against the NSCharacterSet:
That method works for this particular test, but your original question dealt
with interpreting a file with several different field separators at once.
Scanners, notwithstanding their weirdness, are tailor-made for this. With
your "string" method you'll need to have a way to track the range of the
actual data, rather than the field separators. It's very doable, of course,
but I think a scanner would be a lot better.
Jonathan
_______________________________________________
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.