我如何拆分此逗號+引號分隔字符串轉換爲一組字符串:正則表達式(JAVA)的幫助
String test = "[\"String 1\",\"String, two\"]";
String[] embeddedStrings = test.split("<insert magic regex here>");
//note: It should also work for this string, with a space after the separating comma: "[\"String 1\", \"String, two\"]";
assertEquals("String 1", embeddedStrings[0]);
assertEquals("String, two", embeddedStrings[1]);
我很好修剪方括號作爲第一步。但問題是,即使我這樣做了,我也不能只用逗號分割,因爲嵌入的字符串可以包含逗號。 也可以使用Apache的StringUtils。
所以你的輸出將總是'串1'和'串,兩'?我想你有逗號分隔,引用封閉的字段。報價是可選的還是必需的? – jabbie 2009-12-22 21:31:17