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

Source: Internet
Author: User

[Html]
<! Doctype html>
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gbk">
<Script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type = "text/javascript"> </script>
<Script type = "text/javascript">
$ (Function (){
$ ("Input: button"). click (function (){
Count ();
});
});
Function count (){
Var str = $ ("input: text"). val (); // get the value in the input box
Var maxlength = 0; // defines the maximum number of times
// 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
While (str! = ""){
Var oldstr = str; // define a new variable for the string
Letter = str. substr (); // use the substr method to obtain the first character of the string.
Var str = str. replace (new RegExp (letter, "g"), ""); // use a regular expression to replace "the same character as the first character" in the string with null
// "Oldstr. length-str. length" indicates the number of the current character and determines whether it is greater than the number of the previous character.
If (oldstr. length-str. length> maxlength ){
Maxlength = oldstr. length-str. length; // assign the current number of characters to the variable maxlength
$ ("Span"). text (letter );
$ ("Em"). text (maxlength );
};
};
};
</Script>
<Style type = "text/css">
Span, em {color: #933; padding: 0 5px ;}
. Text {width: 500px ;}
</Style>
<Title> find the most frequently occurring character in a string </title>
</Head>
 
<Body>
<H2> output a string of the most frequently occurring characters! </H2>
<Input class = "text" type = "text" value = ""/>
<Input type = "button" value = "Search"/>
<P> "<span> search... </span>" appears most times. <em> computing... </em> appears in total. </P>
</Body>
</Html>

<! Doctype html>
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gbk">
<Script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type = "text/javascript"> </script>
<Script type = "text/javascript">
$ (Function (){
$ ("Input: button"). click (function (){
Count ();
});
});
Function count (){
Var str = $ ("input: text"). val (); // get the value in the input box
Var maxlength = 0; // defines the maximum number of times
// 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
While (str! = ""){
Var oldstr = str; // define a new variable for the string
Letter = str. substr (); // use the substr method to obtain the first character of the string.
Var str = str. replace (new RegExp (letter, "g"), ""); // use a regular expression to replace "the same character as the first character" in the string with null
// "Oldstr. length-str. length" indicates the number of the current character and determines whether it is greater than the number of the previous character.
If (oldstr. length-str. length> maxlength ){
Maxlength = oldstr. length-str. length; // assign the current number of characters to the variable maxlength
$ ("Span"). text (letter );
$ ("Em"). text (maxlength );
};
};
};
</Script>
<Style type = "text/css">
Span, em {color: #933; padding: 0 5px ;}
. Text {width: 500px ;}
</Style>
<Title> find the most frequently occurring character in a string </title>
</Head>

<Body>
<H2> output a string of the most frequently occurring characters! </H2>
<Input class = "text" type = "text" value = ""/>
<Input type = "button" value = "Search"/>
<P> "<span> search... </span>" appears most times. <em> computing... </em> appears in total. </P>
</Body>
</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.