Ad

How To Split A String Into Sentences Cocoa

- 1 answer

I have an NSString with a number of sentences, and I'd like to split it into an NSArray of sentences. Has anybody solved this problem before? I found enumerateSubstringsInRange:options:usingBlock: which is able to do it, but it looks like it isn't available on the iPhone (Snow Leopard only). I thought about splitting the string based on periods, but that doesn't seem very robust.

So far my best option seems to be to use RegexKitLite to regex it into an array of sentences. Solutions?

Ad

Answer

Use CFStringTokenizer. You'll want to create the tokenizer with the kCFStringTokenizerUnitSentence option.

Ad
source: stackoverflow.com
Ad