Reputation: 2145
How could I extract a part of an NSString before certain word(s):
For example:
If the keyword set of 'separators' is an NSArray of the following words "Series" and "documentary"
and if the NSStrings where
"Chain two Series documents" <---- I'd like to extract "Chain two"
"Chain documentary documents" <---- I'd like to extract "Chain"
Thanks
Upvotes: 1
Views: 871
Reputation: 1171
Just use Regular Expressions. They are very useful and supported starting from 10.4 !
There is libicucore (libicu on Tiger).
So RegexKitLite is just wrapper for system library.
Upvotes: 1
Reputation:
You can use an NSScanner to scan strings up to the separators that you provide it.
Someone else mentioned NSString's -componentsSeparatedByString, but that would seem inefficient if you're unconcerned about the text after the separator or if you want to check for multiple separators, based on your example.
Upvotes: 4