fcc-Learning Note Convert HTML entities

Source: Internet
Author: User

fcc-Learning Note Convert HTML entities

1> recently studied and practiced the FCC topics. This is really a good comparison, recommended to everyone.

2> address of the Chinese version: https://www.freecodecamp.cn/, English version of the address: https://www.freecodecamp.org

3> this time to write about a JS problem, called convert HTML entities.

The rules require the following:

Converts characters in a string,,, & < > " (double quotation marks), and (single quotation marks) to their corresponding HTML entities.

4> The code I wrote was implemented as follows:

function convert (str) {  //:)  //Regular expression array  var arr=[/&/i,/</i,/>/i,/"/i,/'/I];  The corresponding replacement HTML element  var duiarr=["&", "<", ">", "'", "'";    for (Var i=0;i<arr.length;i++) for     (var j=0;j<str.length;j++)    {      if (arr[i].test (Str[j])) {        str =str.replace (Str[j],duiarr[i]);      }    }   return str;} Convert ("Dolce & Gabbana"); Convert ("Hamburgers < Pizza < Tacos"); Convert ("Sixty > Twelve"); Convert (' Stuff In "quotation marks"); Convert ("Shindler's List"); Convert ("<>"); CONVERT ("abc");

  

  

5> write bad also need to improve, look forward to everyone's point, common progress!

fcc-Learning Note Convert HTML entities

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.