假设我已从EditText检索文本并将其存储在字符串中:
String str = "Hello, I am new to Android.
现在我想以这种方式将文本存储在数组中:
array={"Hello,","I","am","new","to","Android."};
答案 0 :(得分:3)
根据空间拆分字符串并将其存储在数组中。看看
str = "Hello, I am new to Android";
String[] splited = str.split("\\s+");
答案 1 :(得分:0)
您在空格字符上拆分字符串。
String[] array = str.split(" ");
答案 2 :(得分:0)
使用下面的代码行
String [] array = str.split("");
答案 3 :(得分:0)
String string = "Hello, I am new to Android";
String[] parts = string.split(",");
String part1 = parts[0]; // Hello
String part2 = parts[1]; // I am new to Android
String[] partss = part2.split(" ");
String part11 = parts[0]; // I
String part22 = parts[1]; // am
.....