我想根据 "and , and [ and ] and { and } 解析文件中的一长行
例如
{"ColumnTypes":"int32","fstring32","int32"],"ColumnNames":"ProductId",","ProductName","Quantity"]}
我实际上需要两个不同的数组,来自这一行的列类型和列名。我尝试了 string.split("\\W")
但它不起作用。
请指导。提前致谢。
最佳答案
您需要拆分多个 \\W
个字符(添加一个+
),但首先从前面剪掉这些字符,所以你不会得到一个空白的第一个元素:
String[] array = string.replaceAll("^\\W+", "").split("\\W+");
关于Java String.split 多字符分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17320034/