• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

count a particular character in a string

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,


Is there any way, I can get the value or number of particular character in a given string.

Like ...example abe,abc is a given String.

here there is only one ",". likewise there is 2 a's ..


hope someone can help me..

thanks

Philip
 
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You want us to do your homework... It's not a good thing... As for your question just use String classes and it's methods to do what you need. There is a lot of methods that can help you to accomplish your thing.
 
Philip Zac
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Raj,

I have searched the API, But there is no such thing...

Philip
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it is quite easy. There are several ways to do it; in fact a search of JavaRanch will probably reveal old threads about similar problems.
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you didn't read the API very diligently,

no, there's no "now many Xs are there" method,

but there are �
a) what's the index of X (starting at index i)
b) break the string into pieces, using X as a delimiter
c) what's the character at index i

any could be used to answer your question in several lines of code (or one line, if obfuscation is your cup of tea)
 
reply
    Bookmark Topic Watch Topic
  • New Topic