public String[] getStr(String s){
final String[] split = s.split(",");
String[] string = new String[split.length];
String temp = "";
try {
int i=0;
for (final String one : split) {
final boolean isStartSingleQuotes = one.contains("《");
final boolean isEndSingleQuotes = one.contains("》");
if (!temp.isEmpty()) {
if (isEndSingleQuotes) {
temp += "," + one;
final String substring = temp;
string[i]=substring;i++;
temp = "";
} else {
temp += "," + one;
}
continue;
}
if (isStartSingleQuotes) {
if (isEndSingleQuotes) {
string[i]=one;i++;
} else {
temp += one;
}
} else {
string[i]=one;
}
}
} catch (Exception e) {
System.err.printf("解析错误 :" + e.getMessage());
}
return string;
}
java 以逗号分隔将字符串转化为数组,但字符串中包含逗号 例如:QB/T 1361-2014《红烧猪肉类罐头》,GB 1886.71-2015《食品安全国家标准 食品添加剂 1,2-二氯乙烷》
最新推荐文章于 2022-06-30 13:32:14 发布