删除在csv中将值组合在一起的双引号

时间:2014-09-12 01:03:37

标签: java arrays split comma

我希望标题有意义......

基本上我正在阅读像这样的csv:

“空白”,“你好”,“\”John,Bob \“,”Rudy,Judy \“”,“某事”,“这里”

理想情况下,我希望将其存储到一个结果如下的数组中:

    // I'm going to use { } to separate the indexes so it'll be easier to read
    // each of these indexes will eventually be stored into their own array - they can contain multiple values 
    // e.g like John, Bob and Rudy, Judy - they'll be in the same array but will be in index 0 and 1 and so on
    [{"blank"}, {"hello"}, {"John, Bob", "Rudy, Judy"}, {"something"}, {"here"}]

当我打印出数组的值时,它应该是这样的:

    ...
    System.out.println(item)

    // results in: 
    blank
    hello
    John, Bob
    Rudy, Judy
    ...

我的代码中有这样的内容:

    cand2 = (!csv2DArray[i][j].equals(" ")) ? csv2DArray[i][j].split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)") : new String[0];
    System.out.print("Candidate2 for current contest is: ");
    for(String item: cand2) { System.out.println(item); }
    ...

但是当我打印出值时,我得到了这个:

    blank
    hello
    "John, Bob"
    "Rudy, Judy"
    ...

如何删除附有值的双引号?

这有意义吗?我基本上试图比较值(硒UI测试)。因此,它将读取网站上的任何内容,将这些值存储在数组中,然后我将进行比较。

从UI中提取的内容

    ["John, Bob", "Rudy, Judy", ...] 
    // when I check the debugger the values become 
    John, Bob, Rudy, Judy...

我的代码的结果

    [""John, Bob"", ""Rudy, Judy"", ...]
    // when I check the debugger the values become
    "John, Bob", "Rudy, Judy", ...

1 个答案:

答案 0 :(得分:1)

for(String item: cand2) { System.out.println(item.replace ("\"", ""); }