1、忽略双引号中间的分隔符
https://www.cnblogs.com/ae6623/p/4416485.html
需求:解析CSV文件并忽略引号内的逗号
解决方案:
public static void main(String[] args) {
String s = "a,b,c,\"1,000\"";
String[] result = s.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
for (String str : result) {
System.out.println(str);
}
}
输出:
a
b
c
“1,000″
2、将双引号中的分隔符替换成你想要的
String s="2018-07-11,Banner,俄罗斯方块2018新版(iOS),iOS-俄罗斯方-banner,\"1,151,686\",\"1,319\",58.15,0.05,0.03%";
Pattern p = Pattern.compile("(\".*?),(.*?\")");
Matcher m = p.matcher(s);
StringBuffer sb=new StringBuffer();
while(m.find()){
m.appendReplacement(sb,m.group().replace(",", ""));
System.out.println(m.group());
}
m.appendTail(sb);
System.out.println(sb);