replaceAll思想

来源:互联网 发布:淘宝店入驻折800 编辑:程序博客网 时间:2024/06/05 05:00

Pattern.compile(regex).matcher(this).replaceAll(replacement)

//思想:find匹配项,如果找到,就替换,再找,do-while循环找。(如同链表查询)


  public String replaceAll(String replacement) {
        reset();
        boolean result = find();
        if (result) {
            StringBuffer sb = new StringBuffer();
            do {
                appendReplacement(sb, replacement);
                result = find();
            } while (result);
            appendTail(sb);
            return sb.toString();
        }
        return text.toString();
    }


0 0
原创粉丝点击