Forum : i dono how to find unique letters an anybody give some idea plz
Brief description  about Online courses   join in Online courses
View sriaruna  chandrasekaran 's Profile

i dono how to find unique letters an anybody give some idea plz

can u give any sample or method to find unique letters in string plz.....
Asked by sriaruna chandrasekaran | Jun 2, 2010 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
function unique()
{

// Step 1: total ASCII characters=256, so take array of size 256, from 0-255, first time fill all positions with '0'

a = new Array(255);
count=0;
k=0;
str = document.formname.fieldname.value; // string to check.

for(i=0 ; i<255 ; i++)
{
a[i]=0;
}

// Step 2: whenever any character comes, i am incrementing its ASCII position.

for(i=0 ; i<str.length ; i++)
{
k=String.charCodeAt(str[i]);
a[k]++;
}

// Step 3: Checking which position is equal to '1' and then fetch corresponding ASCII character.

for(i=0 ; i<255 ; i++)
{
if(a[i] == 1)
{
document.write(String.fromCharCode(i)+"&nbsp;&nbsp;");
count++;
}
}
document.write("<br />Total Number Of Unique Letters In A String = "+count);
}
Jun 7, 2010