我正在用Java阅读文件,并想用引号内的值分隔每一行。例如,一行将是...
“ 100”,“ this”,“ a”,“ test”
我希望数组看起来像..
[0] = 100
[1] = this, is
[2] = a
[3] = test
我通常按逗号分割,但是由于某些字段包含逗号(在上面的示例中为位置1),因此它并不适用。
谢谢。
您可以执行以下操作
String yourString = "\"100\",\"this, is\",\"a\",\"test\"";
String[] array = yourString.split(",\"");
for(int i = 0;i<array.length;i++)
array[i] = array[i].replaceAll("\"", "");
最后,数组变量将是所需的数组
输出:
100
this, is
a
test
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句