我正在读取Java中的文件,并希望将每行除以引号内的值.例如,一条线将是......
"100","this,is","a","test"
我希望数组看起来像..
[0] = 100
[1] = this, is
[2] = a
[3] = test
Run Code Online (Sandbox Code Playgroud)
我通常用逗号分隔,但由于某些字段包含逗号(上例中的位置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("\"", "");
Run Code Online (Sandbox Code Playgroud)
最后数组变量将是所需的数组
输出:
100
this, is
a
test
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1481 次 |
| 最近记录: |