aspose file tools
The moose likes Beginning Java and the fly likes Parsing Characters? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Parsing Characters?" Watch "Parsing Characters?" New topic
Author

Parsing Characters?

Sam Bluesman
Ranch Hand

Joined: Nov 21, 2004
Posts: 188
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 ]

Moosey knows best
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24051
    
  13

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.


[Jess in Action][AskingGoodQuestions]
Sam Bluesman
Ranch Hand

Joined: Nov 21, 2004
Posts: 188
Thanks. That worked just fine!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parsing Characters?
 
Similar Threads
Date Format Problem And Hashtable ......
Load and execute SQL from multiple line file?
counting specific words from a text file
int vs Strings
Converting Letters to Ascii