Alibabacloud.com offers a wide variety of articles about java carriage return in string, easily find your java carriage return in string information here online.
To replace with a regular expression:
Code fragment:
String documenttxt = entityutils.tostring (Entity, "GBK");//Get DataDocumenttxt=documenttxt.replaceall ("[\\t\\n\\r]", "");//To remove the carriage return line of the content area
Description:
Java Algorithm interview questions: Separate them with carriage return or space in the answer file .,
Package com. swift; import java. io. bufferedReader; import java. io. bufferedWriter; import java. io. fileInputStream; import java. io.
\ R = carriage return = Cr = 13
\ N = line feed = LF = 10
In Windows, press ENTER = to move the cursor to the beginning of a line, line feed = to move the cursor to the next line.
In Linux, line feed = move the cursor to the beginning of
Replace with a regular expression:
Code snippet:
String documentTxt = EntityUtils. toString (entity, "gbk"); // get dataDocumentTxt = documentTxt. replaceAll ("[\ t \ n \ r]", ""); // remove the line breaks in the content area
Note: replaceAll of
"Carriage return" "newline" symbol basic meaning
general
meaning
Symbol
symbol English
control character (meaning)
carriage return
cursor back to bank start
\r
In Java, if we use the processing to separate strings, we will inevitably use the string's split (string regex) function, which we should pay attention to.Many students do this if they want to separate the strings with a carriage return. Here is an
Use the replaceAll method of the String object!ReplaceAll (String regex, String replacement)Replace this string with the given replacement string to match each substring of the given regular expression.Sample code: The code is as follows:Copy code
Original source: http://www.51itong.net/java-string-rn-209.html
There is a string that prints the results as follows:
Hello \ r \ n World
Now you want to replace the \ r \ n with a normal carriage return, and then print again:
Hello
World
can
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.