One JS (6) day to find the most frequently occurring characters in the string

Source: Internet
Author: User

This method cannot test the characters used by regular expressions, such as $ ^ .? \

 

Http://blog.csdn.net/qmzmxfy/article/details/7431488

[HTML] View plaincopyprint?

  1. <! Doctype html>
  2. <Html>
  3. <Head>
  4. <Meta HTTP-equiv="Content-Type" Content="Text/html; charset = GBK">
  5. <Script SRC=Http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" Type="Text/JavaScript"></Script>
  6. <Script Type="Text/JavaScript">
  7. $ (Function (){
  8. $ ("Input: button"). Click (function (){
  9. Count ();
  10. });
  11. });
  12. Function count (){
  13. VaRStr= $ ("Input: Text"). Val (); // obtain the value in the input box
  14. VaRMaxlength=0; // Define the maximum number of times
  15. // Loop: obtain the first character of the string each time, and replace it with null to obtain the number of characters. Until the string is empty
  16. While (STR! = ""){
  17. VaROldstr=Str; // Define new variables for strings
  18. Letter=Str. Substr (); // use the substr method to obtain the first character of the string.
  19. VaRStr=Str. Replace (New Regexp (letter, "G"), ""); // use a regular expression to replace "the same character as the first character" in the string with null
  20. // "Oldstr. Length-Str. length" indicates the number of the current character and determines whether it is greater than the number of the previous character.
  21. If (oldstr. Length-Str. Length>Maxlength ){
  22. Maxlength=Oldstr. Length-Str. length; // assign the current number of characters to the variable maxlength
  23. $ ("Span"). Text (letter );
  24. $ ("Em"). Text (maxlength );
  25. };
  26. };
  27. };
  28. </Script>
  29. <Style Type="Text/CSS">
  30. SPAN, EM {color: #933; padding: 0 5px ;}
  31. . Text {width: 500px ;}
  32. </Style>
  33. <Title>Find the most frequently occurring characters in the string</Title>
  34. </Head>
  35. <Body>
  36. <H2>Output a string of the most frequently occurring characters!</H2>
  37. <Input Class="Text" Type="Text" Value="" />
  38. <Input Type="Button" Value="Search" />
  39. <P>"<Span>Searching...</Span>", A total<Em>Computing...</Em>Times.</P>
  40. </Body>
  41. HTML >

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.