• 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: String subtraction
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: String subtraction


  • Subject: RE: String subtraction
  • From: "Jonathan E. Jackel" <email@hidden>
  • Date: Tue, 25 Mar 2003 12:31:26 -0500

> You could also use NSScanner and then set omitted characters with
> "setCharactersToBeSkipped:" and then you should be able to use
> "scanString:intoString:" to get what you are looking for. That is
> probably better than the above method I suggested.

That won't work quite the way you seem to think. The docs
for -setCharactersToBeSkipped: say: "While an element is being scanned,
however, no characters are skipped." It does not skip the characters in the
middle of a string that is being scanned with -scanString:intoString: It
only ignores them at the beginning and the end.

So if you are going to use a scanner, it would look something like this
pseudocode:

NSString *hello = @"hello world";
NSScanner *scanner = [NSScanner scannerWithString:hello];
[scanner setCharactersToBeSkipped:
[NSCharacterSet characterSetWithCharactersInString:@"aeiou"]];
NSMutableString *newString = [NSMutableString stringWithCapacity:1];
while (![scanner isAtEnd])
{
NSString *aString;
[scanner scanUpToCharactersFromSet:
[scanner charactersToBeSkipped] intoString:&aString];
[newString appendString:aString];
NSLog(newString);
}

Should give the following output:

h
hll
hll w
hll wrld

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.

References: 
 >Re: String subtraction (From: Jeff Disher <email@hidden>)

  • Prev by Date: Secondary doc window connection
  • Next by Date: Re: 3 obj-c/cocoa beginner q's
  • Previous by thread: Re: String subtraction
  • Next by thread: Re: String subtraction
  • Index(es):
    • Date
    • Thread