去除字符串中的空格回車換行等符號


	public static String replaceBlank(String str) {
		String dest = "";
		if (str!=null) {
			Pattern p = Pattern.compile("\\s*|\t|\r|\n");
			Matcher m = p.matcher(str);
			dest = m.replaceAll("");
		}
		return dest;
	}

	/*-----------------------------------
	簡單方法 :String s = "你要去除的字符串";

	        1.去除空格:s = s.replace('\\s','');

	        2.去除回車:s = s.replace('\n','');

	這樣也可以把空格和回車去掉,其他也可以照這樣做。

	注:\n 回車(\u000a) 
	\t 水平制表符(\u0009) 
	\s 空格(\u0008) 
	\r 換行(\u000d)*/

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM