You can do this in one line. For example, this counts the number of spaces:
NSUInteger numberOfOccurrences = [[yourString componentsSeparatedByString:@" "] count] - 1;
More Related Contents:
- Load R package from character string
- Converting escaped UTF8 characters back to their original form
- If “a == b” is false when comparing two NSString objects
- Remove last character from string. Swift language
- Replace substring of NSAttributedString with another NSAttributedString
- How to get the number of characters in a string
- Strip Non-Alphanumeric Characters from an NSString
- NSString – Convert to pure alphabet only (i.e. remove accents+punctuation)
- +[NSString stringWithString:] — what’s the point?
- What is the output of the following code in C? [closed]
- How to get pixel data from a UIImage (Cocoa Touch) or CGImage (Core Graphics)?
- Cocoa: What’s the difference between the frame and the bounds?
- Parse usable Street Address, City, State, Zip from a string [closed]
- “The argument type ‘String?’ can’t be assigned to the parameter type ‘String'” when using stdin.readLineSync()
- Format a Go string without printing?
- C++/CLI Converting from System::String^ to std::string
- In Bash, how can I check if a string begins with some value?
- Converting a string to an NSDate
- Bash: Split string into character array
- Replacing characters in Ant property
- Objective C NSString* property retain count oddity
- Open Source Cocoa/Cocoa-Touch POP3/SMTP library?
- Generate a random alphanumeric string in Cocoa
- Arguments in @selector
- How do I convert a Vec to Vec?
- Is there an owned version of String::chars?
- How to split a string in Haskell?
- What’s the simplest way to convert from a single character String to an ASCII value in Swift?
- How to use NSScanner?
- scala string.split does not work