aspose file tools*
The moose likes Beginning Java and the fly likes searching strings again Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "searching strings again" Watch "searching strings again" New topic
Author

searching strings again

kevin schmidt
Ranch Hand

Joined: Aug 24, 2001
Posts: 85
Hi,
I posted something about checking strings previously, but I have a different question now. How do you check a string for the number of occurences of a particular character? I want to see if a character occurs more than once or twice. TIA.
kevin
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
char a = yourCharacter
for(int i =0; i < yourString.length(); ++i){
if(a == yourString.charAt(i))
++numberOfOccurences
}
------------------
Bosun
SCJP for the Java� 2 Platform


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Rikard Qvarforth
Ranch Hand

Joined: Jul 10, 2001
Posts: 107
Hi,look in to the Text class. Or you could do one with the String buffer charAt function, or maby stringtokenizer ?
cheers Rille
Rikard Qvarforth
Ranch Hand

Joined: Jul 10, 2001
Posts: 107
and yes charat in the String class also..
ps you are fast Bosun Bello

Rille
kevin schmidt
Ranch Hand

Joined: Aug 24, 2001
Posts: 85
thanks, works awesome
kevin
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: searching strings again