Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String indexing

 
Brian Turner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
Thanks,
Brian Turner
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Brian,
The method String.charAt(int index) should do what you want.
Michael Morris
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also convert the String into a char array using the toCharArray() method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic