• 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: Newbie Question: Find spaces inside a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
References: 
 >Newbie Question: Find spaces inside a string (From: Julian Sanchez <email@hidden>)
 >Re: Newbie Question: Find spaces inside a string (From: Manfred Bergmann <email@hidden>)

  • Prev by Date: Currently used locale
  • Next by Date: Custom tooltips
  • Previous by thread: Re: Newbie Question: Find spaces inside a string
  • Next by thread: Re: Newbie Question: Find spaces inside a string
  • Index(es):
    • Date
    • Thread