将[string,string]转换为Array

时间:2012-01-16 21:03:38

标签: java android arrays string

大家好,我有这个字符串:

[JOLLY BLU at STAY SHIP,  Voy: 0275/11]

如何在String []

中转换此字符串
value[0] = "JOLLY BLU at STAY SHIP";
value[1] = "Voy: 0275/11";

非常感谢

2 个答案:

答案 0 :(得分:7)

str = str.substring(1, str.length() - 1); // cut [ and ] off
String[] parts = str.split(",");

答案 1 :(得分:4)

String s = "[JOLLY BLU at STAY SHIP,  Voy: 0275/11]";
String temp = s.replace("[", "").replace("]", "");
// or String temp = s.substring(1, s.length() - 1);
String[] sArray = temp.split(",");
sArray[1] = sArray[1].trim(); // remove the whitespaces around the string