Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split a string into sentences cocoa

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?

like image 735
Kenny Winker Avatar asked Dec 13 '22 00:12

Kenny Winker


1 Answers

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

like image 71
Peter Hosey Avatar answered Dec 30 '22 17:12

Peter Hosey