java去除字符串中的空格、回车、换行符、制表符

http://cindysaj.iteye.com/blog/299476


java去除字符串中的空格、回车、换行符、制表符
import java.util.regex.Matcher; 
import java.util.regex.Pattern; 

public class StringUtil { 

public static void replaceBlank() 
{ 
   Pattern p = Pattern.compile(“\\s*|\t|\r|\n”); 
   String str="I am a, I am Hello ok, \n new line ffdsa!"; 
   System.out.println("before:"+str); 
   Matcher m = p.matcher(str); 
   String after = m.replaceAll(""); 
   System.out.println("after:"+after); 
} 

public static void main(String[] args) { 
     replaceBlank(); 
   } 

} 



一个单引号变成两个单引号
p = Pattern.compile("\'");
m = p.matcher(columnValue);
columnValue = m.replaceAll("\'\'");

猜你喜欢

转载自panyongzheng.iteye.com/blog/1610240