• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

searching strings again

 
kevin schmidt
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
char a = yourCharacter
for(int i =0; i < yourString.length(); ++i){
if(a == yourString.charAt(i))
++numberOfOccurences
}
------------------
Bosun
SCJP for the Java� 2 Platform
 
Rikard Qvarforth
Ranch Hand
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and yes charat in the String class also..
ps you are fast Bosun Bello

Rille
 
kevin schmidt
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, works awesome
kevin
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic