Use JS to obtain the most frequently used letters in the string.

Source: Internet
Author: User


[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Supplement:
Copy codeThe Code is as follows:
Eval ("str = str. replace (/" + getStr + "/g ,'')");

Many people may want to write str = str. replace (/getStr/g, ") in this way, but the result is wrong. Why? In this sentence, the expression matches the getStr string instead of the first letter pointed to by getStr. The eval method can be used to avoid this problem (first, getStr gets the first letter to which it points, and uses a string to connect "str = str. replace (/"+ getStr +"/g, ")", and finally execute this code in eval, that is, explain the Javascript code first, and then execute it ).

Because of the poor eval performance, error-prone and poor readability. We recommend that you change eval ("str = str. replace (/" + getStr + "/g,") ":
Str = str. replace (new RegExp (getStr, "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.