Re: Newbie Question: Find spaces inside a string
Re: Newbie Question: Find spaces inside a string
- Subject: Re: Newbie Question: Find spaces inside a string
- From: Shaun Wexler <email@hidden>
- Date: Sat, 29 Oct 2005 01:52:12 -0700
On Oct 25, 2005, at 10:12 PM, Manfred Bergmann wrote:
Actually, there are some alternatives to the NSScanner method.
You could so something like this:
NSArray *components = [myString componentsSeparatedByString:@" "];
int count = ([myString length] - ([components count] -1));
But I do not know what happend if there are more than one space
character in a row. This has to be tested.
Or this:
NSMutableString *mutable = [NSMutableString
stringWithString:myString];
int spaces = [mutable replaceOccurencesOfString:@" " withString:@""
options:0 range:NSMakeRange(0,[mutable length])];
Not quite; you'd need to do this iteratively to handle multiple spaces:
while ([mutable replaceOccurrencesOfString:@" " withString:@" "
options:nil range:NSMakeRange(0, [mutable length])]);
--
Shaun Wexler
MacFOH
http://www.macfoh.com
"Things should be described as simply as possible, but no simpler." -
Albert Einstein
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden