1. 程式人生 > >替換 html中換行符、空格 ;去除字串中的空格\\s*,回車\n,換行符\r,製表符\t

替換 html中換行符、空格 ;去除字串中的空格\\s*,回車\n,換行符\r,製表符\t

1、替換 html中換行符、空格

/** 替換 html中換行符、空格 */

public static String repText(String str) throws Exception {
    String r = "";
    r = str.replaceAll("<br/>", "\n");
    r = r.replaceAll("&nbsp;", " ");

    return r;

}

2、去除字串中的空格\\s*,回車\n,換行符\r,製表符\t

public static String isReplaceStr(String str_content) {
    String r = ""
; Pattern p = Pattern.compile("\\s*|\t|\r|\n"); Matcher m = p.matcher(str_content); r = m.replaceAll(""); return r; }