0
点赞
收藏
分享

微信扫一扫

JAVA-将字符串中的英文括号替换为中文括号

Separes 2022-02-11 阅读 83
// 将英文括号替换成中文括号
    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;
    }
举报

相关推荐

0 条评论