• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: multiple componentsSeparatedByString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: multiple componentsSeparatedByString


  • Subject: RE: multiple componentsSeparatedByString
  • From: Koen van der Drift <email@hidden>
  • Date: Sat, 23 Nov 2002 12:34:03 -0500

>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@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.

  • Follow-Ups:
    • Re: multiple componentsSeparatedByString
      • From: Jonathan Jackel <email@hidden>
    • RE: multiple componentsSeparatedByString
      • From: Koen van der Drift <email@hidden>
References: 
 >RE: multiple componentsSeparatedByString (From: "Jonathan E. Jackel" <email@hidden>)

  • Prev by Date: Re: Address Book API - Person vs Company
  • Next by Date: Re: An interesting localisation issue
  • Previous by thread: RE: multiple componentsSeparatedByString
  • Next by thread: RE: multiple componentsSeparatedByString
  • Index(es):
    • Date
    • Thread