File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 Android Security Essentials Live Lessons this week in the Android 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: searching strings again
 
Similar Threads
Strings in java.
Getting 404 even when the path looks ok
a question
Test a specific char in a string
Create a file and then writes it text