Java 将字符串中的英文括号转成中文括号
@Test
public void mysqlTest6() throws Exception {
String a="AdEFg(Hi)";
String b="31007(689)";
System.out.println(replaceStr(a));
System.out.println(replaceStr(b));
}
// 将英文括号替换成中文括号
private String replaceStr(final String str) {
String newNode = null;
String allConvertNode = null;
// 替换英文括号的时候因为正则表达式问题,英文前括号和后括号的前边都要加上\\
if (str.contains("(") && str.contains(")")) {
newNode = str.replaceAll("\\(", "(");
allConvertNode = newNode.replaceAll("\\)", ")");
} else if (str.contains("(") && !str.contains(")")) {
allConvertNode = str.replaceAll("\\(", "(");
} else if (!str.contains("(") && str.contains(")")) {
allConvertNode = str.replaceAll("\\)", ")");
} else {
allConvertNode = str;
}
return allConvertNode;
}
输出结果:
AdEFg(Hi)
31007(689)
还没有评论,来说两句吧...