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
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.