Let's take a look at a few examples:
Example 1:
public class Test {
public static void Main (string[] args) {
String s = "' SDS GDASDA" + "\ n" + "Edaeafd '";
System.out.println ("Before conversion:" +s);
s = S.replaceall ("\r|\n", "");
System.out.println ("After conversion:" +s);
}
}
Output results:
Before conversion: ' SDS GDASDA
EDAEAFD '
After conversion: ' SDS GDASDAEDAEAFD '
Looking at an example:
Example 2:
System.out.println ("\ R output:" + "abc" + "\ r" + "abc");
SYSTEM.OUT.PRINTLN ("\\n Output:" + "abc" + "\ n" + "abc");
The above two sentences are in the same format as the console output:
\ r output: ABC
Abc
\ r output: ABC
Abc
So does it mean that \ r is equal to \ n?
Example 3:
public class Test {
public static void Main (string[] args) {
String s = "' SDS GDASDA" + "\ n" + "Edaeafd '";
System.out.println ("Before conversion:" +s);
s = S.replaceall ("\ R", "");
System.out.println ("After conversion:" +s);
}
}
Before conversion: ' SDS GDASDA
EDAEAFD '
After conversion: ' SDS GDASDA
EDAEAFD '
The output shows that \ r is not equal to \ n. hi.
So what's the difference between them?
Example 4:
public class Test {
public static void Main (string[] args) {
String s = "' SDS GDASDA" + "\n\r" + "Edaeafd '";
System.out.println ("Before conversion:" +s);
s = S.replaceall ("\r|\n", "");
System.out.println ("After conversion:" +s);
}
}
Output results:
Before conversion: ' SDS GDASDA
EDAEAFD '
After conversion: ' SDS GDASDAEDAEAFD '
You can see that \ r represents a carriage return, \ n represents a second line (\ r) called carriage return Carriage return; \ n = new line \ ew Line)
We can do in one experiment:
Example 5:
public class Test {
public static void Main (string[] args) {
String s = "' SDS GDASDA" + "\ r \ n" + "Edaeafd '";
System.out.println ("Before conversion:" +s);
s = S.replaceall ("\r|\n", "");
System.out.println ("After conversion:" +s);
}
}
Output results:
Before conversion: ' SDS GDASDA
EDAEAFD '
After conversion: ' SDS GDASDAEDAEAFD ' in
In Example 4 to Example 5, we just changed the position of the \n\r of the string s to \ r \ n, but found that the example 4 output resulted in one more line of space.
As for why example 4 and example 5 output will have this difference is the difference between \ r \ n and \n\r, this is a better answer on the net:
Enter+newline with different platforms:
Windows: \ r \ n
Mac: \ r
Unix/linux: \ n
In "abc" + "\n\rdef", \n\r don't match any platform,so it is considered as \ r (which match unix/linux and Mac), so there are two new lines.
In "abc" + "\r\ndef" \ r \ n matches the Windows Platform,so it is considered as only one new line.
SCIM crushed, so just 中文版.
About \ t It is equivalent to pressing the TAB key.