• Post Reply Bookmark Topic Watch Topic
  • New Topic

Parsing Characters?  RSS feed

 
Sam Bluesman
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lets say im reading a line from a text file. In the case on wanting to put integers that are in a string I read in into an integer, the following snippet of code works fine.



obvisouly the emphasis is on the Integer.parseInt()


Now, lets say i want to read in letters that are seperated by spaces that are to be placed into a char array called, say, letters.



Is it possible to PARSE these in as characters into a char array or do these have to be passed in as STRINGS into a String array?

Thanks
[ November 02, 2005: Message edited by: Sam Bluesman ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If "letter" is a one-character String, then to get that character as a 'char' you use the charAt() method:

char c = letter.charAt(0);

This method works for Strings of any length, of course.
 
Sam Bluesman
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. That worked just fine!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!