App inventor 2: How to split at spaces

Peggy Chang picture Peggy Chang · Oct 11, 2015 · Viewed 13.3k times · Source

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.

enter image description here

enter image description here

Answer

Rami picture Rami · Oct 11, 2015

You can use String.split()

String yourString = "Hello World";

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