Method for carriage return line breaks in a Java replacement string _java

Source: Internet
Author: User

To replace with a regular expression:

Code fragment:

String documenttxt = entityutils.tostring (Entity, "GBK");//Get Data
Documenttxt=documenttxt.replaceall ("[\\t\\n\\r]", "");//To remove the carriage return line of the content area

Description: The ReplaceAll of the string class has a regular substitution function. \ t is a tab \ n is a newline \ r for carriage return


Java Regular use:

Example method:

Copy Code code as follows:

public void Parsetxt (String content) {
Pattern p = pattern.compile (CONFIG.ARTICLEPTN);
Matcher Matcher = p.matcher (content);
while (Matcher.find ()) {
System.out.println (Matcher.group (1));
}

}

Description: Just remember the pattern class, and its static method Complie parse a regular expression to generate an object.

Then use the model to match the string, get a matcher, and traverse all the matches through the Matcher find method.

Group is the set in the regular expression and the () expression. Group (0) is the original string, Gourp (1) is the first group to match ... That is, the index of the group that is matched starts at 1.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.