Matching start of words in NSString

Is there a method built into NSString that tokenizes a string and looks for the start of each token? the method compare

seems to only execute the beginning of the string, and usage rangeOfString

is not really sufficient because it has no knowledge of tokens. Right now I think the best way to do this is to call

[myString componentsSeparatedByString:@" "]

      

and then move on to the resulting array by invoking the comparison of each component of the string. Is this inline and I just missed it?

+1


source to share


2 answers


Using a CFStringTokenizer for, um, tokenizing strings will be more reliable than splitting into @" "

, but finding the results is still up to you.



+5


source


You can look in RegexKit Lite:

http://regexkit.sourceforge.net/#RegexKitLite/

Although it is a third party library, it is basically a very small (one class) wrapper built around a fairly powerful built-in regex engine.



It looks like it would be more useful since you could have non-capturing expressions matching the delimiter markers and then the capturing part includes or does not include the text you are looking for along with the rest of the text between the tokens. If you haven't used regular expressions before, you will need to read some kind of link, but just know that you can separate the relevant patterns from the content you want to see with cryptic yet very powerful syntax.

I'm also not sure if you can use a CFStringTokenizer on an iPhone, since the iPhone specific document set doesn't have a reference to it.

+2


source







All Articles