I need get all the words of a UITextView of individual form. In an array for example.
Asked
Active
Viewed 660 times
1 Answers
2
Simple.. Just use this if you have one space between two words:
NSArray *words = [textview.text componentsSeparatedByString:@" "];
OR if there is the possibility of multiple spaces between words:
NSArray *words = [textview.text componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]

Salman Zaidi
- 9,342
- 12
- 44
- 61
-
if it has two or multiple spaces what you can do – codercat Nov 29 '13 at 11:24
-
Well, there can be unlimited cases just like double spaces.. It all depends on data entry. format of data. :) – Salman Zaidi Nov 29 '13 at 11:27
-
see the edited post. @iDev now it will take care of multiple spaces – Salman Zaidi Nov 29 '13 at 11:29
-
1This is a naive solution. Not all languages separate words with a space, for example. If you're tokenizing natural languages, look at the `NSString` method `enumerateSubstringsInRange:options:usingBlock:` or use a `CFStringTokenizer` – David Snabel-Caunt Nov 29 '13 at 11:36