Java line break
This is because, by default, "n" is used for line change on the interface, which is a line break for LINUX and UNIX. In windows, the linefeed is "rn". Therefore, when writing a String object to a file, the linefeed should write n completely into rn.
| The code is as follows: |
Copy code |
|
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 ";
1. Remove spaces: s = s. replace ('\ S ','');
2. Remove the carriage return: s = s. replace ('N ','');
In this way, the space and press enter can be removed, and others can be taken as well.
Note: n press enter (u000a)
T horizontal tab (u0009)
S space (u0008)
R line feed (u000d )*/
} |