Replace functions in JavaScript

Source: Internet
Author: User

Copy to ClipboardReference: [www.bkjia.com] public string EnCode (string content)
{
String str1 = content. Replace ("<", "<");
String str2 = str1.Replace (">", "> ");
String str3 = str2.Replace ("'", "& apos ;");
String str4 = str3.Replace ("","");
String str5 = str4.Replace ("\ r \ n", "<br> ");
String str6 = str5.Replace ("\"",""");
String str7 = str6.Replace ("&","&");
Return str7;
}

Public string UnCode (string content)
{
String str1 = content. Replace ("&","&");
String str2 = str1.Replace (""","\"");
String str3 = str2.Replace ("<br>", "\ r \ n ");
String str4 = str3.Replace ("","");
String str5 = str4.Replace ("'", "& apos ;");
String str6 = str5.Replace (">", "> ");
String str7 = str6.Replace ("<", "<");
Return str7;

This is used for SQL escape character conversion. At first, we found that only the first one was converted. At that time, I was depressed. In the dumbest way, I made two loops to replace the others. Later, you can change it to string str1 = content. Replace/& amp;/g, "&"); to Replace all.

Copy to ClipboardReference: [www.bkjia.com] public string EnCode (string content)
{
String str1 = content. replace (/</g, "<");
String str2 = str1.replace (/>/g, "> ");
}

Related Article

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.