我的CSV文件看起来像这样
"Gates Nissan of Richmond" , "L2T Media, Llc" , "7000000", "--"
我想从CSV
中的"L2T Media, Llc"
中删除逗号(,)
这样,我的输出将为"L2T Media Llc"
如何在Java编码中执行此操作?
答案 0 :(得分:1)
您可以尝试这样的事情:
String str = "\"Gates Nissan of Richmond\" , \"L2T Media, Llc\" , \"7000000\", \"--\"";
List<String> items = new ArrayList<String>();
for(String item : Arrays.asList(str.substring(1, str.length()-1).split("\"+\\s*,\\s*\"+")))
items.add("\"" + item.replace(",", "") + "\"");
System.out.println(items);
<强>输出:强>
["Gates Nissan of Richmond", "L2T Media Llc", "7000000", "--"]
答案 1 :(得分:0)
基于this answer:
public static void main(String[] args) {
String s = "\"Gates Nissan of Richmond\" , \"L2T Media, Llc\" , \"7000000\", \"--\"";
String[] splitted = s.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
for(String item : splitted) {
item.replaceAll(",", "");
}
}