Java Escape Special characters

Source: Internet
Author: User

 Public classHtmlutilstest { Public Static voidMain (string[] args) {String specialstr= "The upstream of the animated film--"; String str1= Htmlutils.htmlescape (SPECIALSTR);//① conversion to HTML escape character representationSystem.out.println (STR1); String str2= Htmlutils.htmlescapedecimal (SPECIALSTR);//② conversion to data escape representationSystem.out.println (STR2); String STR3= Htmlutils.htmlescapehex (SPECIALSTR);//③ conversion to hexadecimal data escape representationSystem.out.println (STR3); //④ the inverse of the string in the face of escapeSystem.out.println (Htmlutils.htmlunescape (str1));        System.out.println (Htmlutils.htmlunescape (str2));        System.out.println (Htmlutils.htmlunescape (STR3)); // http://www.blogjava.net/i369/articles/236830.html        //The Htmlutils provides three escape methods://Method Description//the static string Htmlescape (string input) escapes the HTML special character as an HTML universal escape sequence;//static string Htmlescapedecimal (string input) escapes the HTML special character as a band #//the decimal data escape sequence;//static string Htmlescapehex (string input) escapes the HTML special character as a band #//the hexadecimal data escape sequence;//        //In addition, Htmlutils provides a way to restore escaped content: Htmlunescape (String//input), which can restore the contents of the above three escape sequences. Run the above code and you'll see the following output://        //Str1:&lt;div id=&quot;testdiv&quot;&gt;test1;test2&lt;/div&gt; //str2:<div id= "Testdiv" >test1;test2</div>//str3:<div id= "Testdiv" >test1;test2</div>//<div id= "Testdiv" >test1;test2</div>//<div id= "Testdiv" >test1;test2</div>//<div id= "Testdiv" >test1;test2</div>//        //        //        //you just use Htmlutils to escape the UserName and address of listing 1, and the final output of the HTML//the page will not be destroyed.     }}

Java Escape Special characters

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.