import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StringUtils {
/**
* 字符串序列化
* @param str
* @return
*/
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;
}
/**
*
* @param str
* @param from 被替换的
* @param tostr 替换成
* @return
*/
public static String replaceBlank(String str,String from,String tostr) {
String dest = "";
if (str!=null) {
Pattern p = Pattern.compile(from);
Matcher m = p.matcher(str);
dest = m.replaceAll(tostr);
}
return dest;
}
public static void main(String[] args) {
System.out.println(StringUtils.replaceBlank("just do it!"));
}
}