• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Distinguishing characters in a String

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, im need to find a way of distinguishing between individual characters in a String according to their position in the String. I need them to be then stored in another Stringso that i can then analyse and rearrange them.
A String contains to word "Bob"
i would then like to have three other Strings (first, second and third) that hold the first second and third characters in the word:
eg.
first = b
second = o
third = b
Thanks
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This sounds like homework. I bet you can figure this out for yourself if you try. Take a look at the javadocs (API) for the String class and see what it can do. There are several ways you could do this.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One simple way would be, to use the toCharArray() method in the String class , to get the string content to be represented as a character array and then the rest is simple to access the array memebers.
The other way could be to use the substring() method to get single character at a time, serially.
Hope this helps you.
regards
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The documentation that Micheal referred to is available at http://java.sun.com/j2se/1.4.2/docs/api/
You'll perhaps want to make use of the indexOf, charAt, and substring methods of the String class.
If you've further questions, do post them here. Just try to be specific about what part of the program you're trying to figure out.
 
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic