2012-01-16 168 views
1

大家好我有這個字符串:變換[字符串,字符串]數組

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

我怎麼可以把這個字符串中的String []

value[0] = "JOLLY BLU at STAY SHIP"; 
value[1] = "Voy: 0275/11"; 

三江源多

+0

爲什麼這個標籤爲「android」? –

+0

@savinos因爲Android使用Java作爲編程語言。 –

+1

是的,我的意思是這不是特定於android以任何方式 –

回答

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

有一個錯字,分隔符是「,」而不是「;」 –

+0

非常感謝你! –

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 
+0

第三行應該是temp.split –

+0

是的,你是對的:) –

+0

非常感謝你! –