如何在UITextView中的空格之间获取文字? [重复]

时间:2022-08-28 21:44:40

This question already has an answer here:

这个问题在这里已有答案:

I need get all the words of a UITextView of individual form. In an array for example.

我需要获得单个形式的UITextView的所有单词。例如,在数组中。

1 个解决方案

#1


3  

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

#1


3  

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