Forum : find unique letters in string
Brief description  about Online courses   join in Online courses
View SARITA  DUBEY 's Profile

find unique letters in string

dear teacher, how to find the unique letters in string.. i tried a lot but not able to solve..please help me.

Thank you.
Asked by SARITA DUBEY | Jun 9, 2010 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
hi Sarita,
below is function for unique letter in string.

function check()
{
var string=document.form1.txt1.value;
if(Number(string)||string=="")
{
alert("Enter a string");
document.form1.txt1.value="";
}
else
{
var count=0;
string=string.split('');
var len=string.length;
alert("The entered string has "+len+" letters.");
for(i=0;i<len;i++)
{
for(j=i+1;j<=len;j++)
{
if(string[i]==string[j])
{
count++;
break;
}
}
}
var unique=len-count;
alert("The number of unique characters the string "+string+" has is "+unique);
Jun 10, 2010