Possible Duplicate:
check number of a given character occurence in a String
I’m trying to make a program that checks how many times a character occurs in a string.
I managed to convert it to ASCII but I also want to be able to count how many time a certain character or an ASCII value appears in the string.
String myString = "Hello.";
for (int i=0;i<myString.length();i++){
char c = myString.charAt(i);
int j = (int) c;
System.out.println("ASCII OF "+c +" = " + j + ".");
}
If you have any other alternative apart from converting to ASCII, please let me know.
How about this:
This could easily be turned into a method to use many times: