App inventor 2: How to split at spaces

笑着哭i 提交于 2019-12-02 11:31:20

问题


I have a small question. I want to split the text at the space.

eg:

"Hello World "

should be

"Hello" ,"World"

I tried to use "\r" ,but it is no use. I don't know what can I do.

Please help me. Thank you very much. I try 2 way to split the text. But the list length always 1.


回答1:


You can use String.split()

String yourString = "Hello World";

String[] result = yourString.split(" ");
result[0]; //"Hello"
result[1]; //"World"



回答2:


what about using the split at spaces block?

Divides the given text at any occurrence of a space, producing a list of the pieces.

A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook http://www.appinventor.org/book2 ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks. There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro and the aia files for the projects in the book are here: http://www.appinventor.org/bookFiles
How to do a lot of basic things with App Inventor are described here: http://www.appinventor.org/content/howDoYou/eventHandling .

Also do the tutorials http://appinventor.mit.edu/explore/ai2/tutorials.html to learn the basics of App Inventor, then try something and follow the Top 5 Tips: How to learn App Inventor




回答3:


Why you need to use add item to list? Just use split at space function or split text at. Below is example of code. The result of length of list is 2:



来源:https://stackoverflow.com/questions/33061810/app-inventor-2-how-to-split-at-spaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!