Forum : Number of Unique Letters in String....
Brief description  about Online courses   join in Online courses
View Avraham  Venismach 's Profile

Number of Unique Letters in String....

I have been searching for a lesson on how to do this. Any suggestions?
Asked by Avraham Venismach | Feb 25, 2010 |  Reply now
Replies (3)
View sucheta patra 's Profile
This Code Is nt working in internet explorer.
help me out.
Apr 8, 2010
View teacher siliconindia 's Profile
Hi Avraham,

This question you can solve using loop.
logic is you have to use check the existence of each character, if a character coming once only that is unique character.


Regards,

Mar 3, 2010
View sanjay s nair 's Profile
<html>
<head>
<title>Number of unique letters in a string</title>
<script type="text/javascript">
function uniquecount(str){
var newString = "";
var strLength = str.length;
var tempStr = new Array();
var check = false;
for (i=0;i<strLength;i++){
if(tempStr.length > 0){
for (j=0;j<tempStr.length;j++){
if(tempStr[j]==str[i]){
check = true;
break;
}
}
if(check == false){
tempStr.push(str[i]);
}
check = false;
}else{
tempStr.push(str[i]);
}
}

newString = tempStr.join("");
alert("Passed String = "+str);
alert("Stripped String = "+newString);
alert("Stripper String Count = "+newString.length);
}
</script>
</head>
<body>
<form name=form1>
Enter a string: <input type=text name=str > <input type=button name=submit value="Get Unique Count" onclick="uniquecount(document.form1.str.value)">
</form>
</body>
</html>
Mar 1, 2010