-
countin unique chars !
Hi everyone !
Im new in this forum!
Im having a problem. I want to count the unique characters of a String(Ascii Image) without using Arrays .
I've already tried this, but no result :S .
Code:
public int getUniqueChars(){
String imgchar = Image; //Image is the original asciiImage
for(int i=0;i<imgchar.length();i=i+0){
imgchar=imgchar.replaceAll(Character.toString(imgchar.charAt(i)),"");
}
imgChars = imgchar.length();
return imgChars;
}
-
Help help help please !!!
-
You've bumped your thread after it's been here for only an hour. Please read this link to see why this may have the opposite effect you intended: PatienceIsAVirtue
-
Quote:
Originally Posted by
pauser
Code:
for(int i=0;i<imgchar.length();i=i+0){
It's gonna take a while for i to get to imgchar.length when it's advancing zero characters at a time.
-Gary-
-
I found the solution :D . Sorry, i could not wait :S.
Code:
public int getUniqueChars(){
String imgchars = "";
for(int i=0;i<Image.length();i++){
if(!imgchars.contains(Character.toString(Image.charAt(i))))
imgchars += Character.toString(Image.charAt(i));
}
return imgchars.length();
}