RE: String subtraction
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.