Skip navigation.
 
mlRe: multiple componentsSeparatedByString
FROM : Jonathan Jackel
DATE : Mon Nov 25 00:04:43 2002

> 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_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