Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想从基于 " and , and [ and ] and { and } 的文件中解析一长行
例如
{"ColumnTypes":"int32","fstring32","int32"],"ColumnNames":"ProductId",","ProductName","Quantity"]}
我实际上需要来自此行列类型和列名的两个不同数组。我试过string.split("\\W")了,但它不工作。
string.split("\\W")
请指导。提前致谢。
您需要拆分多个 \\W字符(添加 a +),但首先从前面修剪掉这些字符,这样您就不会得到一个空白的第一个元素:
\\W
+
String[] array = string.replaceAll("^\\W+", "").split("\\W+");
最简单的方法(使用正则表达式)是允许多个非单词字符匹配:
string.split("\\W+")