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

Separes

关注

阅读 83

2022-02-11

// 将英文括号替换成中文括号
    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)

0 0 举报