我需要对此字符串进行标记。
AddItem rt456 4 12 BOOK "File Structures" "Addison-Wesley" "Michael Folk"
我需要
"AddItem","rt456","12","BOOK","File Structures","Addison-Wesley","Michael Folk"
子串。如何使用split()来获取这些令牌?
答案 0 :(得分:0)
List<String> list = new ArrayList<String>();
Matcher m = Pattern.compile("([^\"]\\S*|\".+?\")\\s*").matcher(str);
while (m.find())
list.add(m.group(1));
输出:
[AddItem, rt456, 4, 12, BOOK, "File Structures", "Addison-Wesley", "Michael Folk"]