Most No of Chars Appear in String

Posted by Self-Innovator under JavaScript on 4/10/2012 | Points: 10 | Views : 711 | Status : [Member] | Replies : 5
Hi...
Pls tel me How to find out the no chars apper in a string...
I've tried but strucked..

function FindMostCharInStr(x)
{
var len=x.value.length;
var chars=new Array(len);
var CharRepeatMostTimes;
for (var i=0;i<len;i++)
{
chars=x.value.charAt(i);
}
for(var j=0;j<chars.length;j++)
{
if(chars[j]==chars[j+1])
{
CharRepeatMostTimes++;
}
}
alert(CharRepeatMostTimes);
}


Callin this on OnChange of text box event

Join Hands Change lives
Thanks & Regards
Straight Edge Society



Responses

Posted by: Mani5155 on: 4/10/2012 [Member] Starter | Points: 25

Up
0
Down
try this

function FindMostCharInStr(x)

{

var len=x.value.length;

var chars=new Array(len);

var CharRepeatMostTimes;

for (var i=0;i<len;i++)

{

chars=x.value.charAt(i);

}

for(var j=0;j<chars.length;j++)

{
for(var k=j+1;k<chars.length;k++)
{
if(chars[j]==chars[k])

{

CharRepeatMostTimes++;

}
}

}

alert(CharRepeatMostTimes);

}

Top Forums Authors
Tue, 28-Mar-2017 Authors
Jayakumars
30
Kasani007
10
Ahmedsa
10
All Time Authors
Jayakumars
5760
Karthikanbarasan
3455
Oswaldlily
3300

Latest members | More ...


(Statistics delayed by 5 minutes)
Advertisements