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
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
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
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.