Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Distinguishing characters in a String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Distinguishing characters in a String" Watch "Distinguishing characters in a String" New topic
Author

Distinguishing characters in a String

Nick Collings
Greenhorn

Joined: Dec 02, 2003
Posts: 1
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
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
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.


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Natraj Gudla
Ranch Hand

Joined: Feb 09, 2003
Posts: 34
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
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Distinguishing characters in a String
 
Similar Threads
I am new and need help with this plzzzzzzzzzzz
constructor method help
Letter checking
Paradoxes and Ironies!!!!
String replace