Copy the code code as follows:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author lei
*2011-9-2
*/
public class StringUtils {
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;
}
public static void main(String[] args) {
System.out.println(StringUtils.replaceBlank("just do it!"));
}
/*----------------------------------
Stupid method: String s = "The string you want to remove";
.Remove spaces: s = s.replace('//s','');
.Remove carriage return: s = s.replace('/n','');
This way you can also remove spaces and carriage returns, and you can do the same for other things.
Note: /n Enter (/u000a)
/t horizontal tab (/u0009)
/s space (/u0008)
/r newline(/u000d)*/
}