去空格 :import java.util.regex.Matcher;java
import java.util.regex.Pattern;spa
public class StringUtils {字符串
/**it
*正則class
*/import
public static String replaceBlank(String str) {方法
String dest = "";im
if (str!=null) {static
Pattern p = Pattern.compile("\\s*|\t|\r|\n");co
Matcher m = p.matcher(str);
dest = m.replaceAll("");
}
return dest;
}
public static void main(String[] args) {
System.out.println(StringUtils.replaceBlank("just do it!"));
}
/*-----------------------------------
笨方法:String s = "你要去除的字符串";
1.去除空格:s = s.replace('\\s','');
2.去除回車:s = s.replace('\n','');