objective c - Separate Full Sentences in a block of NSString text -


I am trying to use regular expression to separate full sentences in a large section of text. I can not use the components of the learned bancarket inset because it will fail with the sentences that are ending clearly?!, !!, ... I have seen some external sections to separate components, but I add an external library I like to do this without.

Here is a sample input Hi, I'm testing what's up? Wow!! This is the best, and I am happy.

Output should be an array

The first element: Hello, I am testing.

Second element: How are you?

Third element: Wow !!

Next element: This is the best, and I am happy.

This is what I have, but as I said, I should not do what my intentions are. Perhaps a regular expression will do a better job here.

  - (NSArray *) getArrayOfFullSentencesFromBlockOfText: (NSString *) TextBox {NSMutableCharacterSet * characterSet = [[NSMutableCharacterSet alloc] init]; [Add Character addharactersInstring: @ ".?!"]; NSArray * sentenceArray = [separate textbook components from Cincinnati: character]; Return Sentence; }   

Thanks for your help,

to use

You want - [NSString enumerateSubstringsInRange: Options: usingBlock:] with NSStringEnumerationBySentences option. This will give you every sentence, and it does not do this in a language-conscious way.

  NSArray * fullSentencesFromText (NSString * text) {NSMutableArray * Result = [NSMutableArray array]. [Text enumerateSubstringsInRange: NSMakeRange (0, [text length]) Options: NSStringEnumerationBySentences usingBlock: ^ (NSString * -String, NSRange substringRange, NSRange enclosingRange, BOOL * off) {[result addObject: substrings]; }]; Return results; }   

Note, in the test, the backspace appears after every string break. You want to get them out.

Comments