File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes String indexing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String indexing" Watch "String indexing" New topic

String indexing

Brian Turner

Joined: Mar 18, 2002
Posts: 4
Can someone tell me how to extract single caharacter from a a string?
for example: I have an String array of 9 digit numbers entered at the command line. I want to extract each of the 9 numbers from he string in each cell of the array and place them into another array singly.
command line entry String args[] in main = 123456789,987654321...
first command line number 123456789 goes into an int array
[0] = 1
[1] = 2
[2] = 3...
Brian Turner
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Brian,
The method String.charAt(int index) should do what you want.
Michael Morris

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
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
You can also convert the String into a char array using the toCharArray() method.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Consider Paul's rocket mass heater.
subject: String indexing
It's not a secret anymore!