在Java中使用引号之间的值拆分字符串

use*_*194 6 java string split

我正在读取Java中的文件,并希望将每行除以引号内的值.例如,一条线将是......

"100","this,is","a","test"

我希望数组看起来像..

[0] = 100
[1] = this, is
[2] = a
[3] = test
Run Code Online (Sandbox Code Playgroud)

我通常用逗号分隔,但由于某些字段包含逗号(上例中的位置1),因此不太合适.

谢谢.

Nab*_*bin 2

您可以执行以下操作

    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)