How can I parse a get a char from a string, say i'm reading each letter from a string using substring (String a=line.substring(x,x+1);
//reads one letter at a time
how can i get that one letter to a char?
then from a char to an int?
Printable View
How can I parse a get a char from a string, say i'm reading each letter from a string using substring (String a=line.substring(x,x+1);
//reads one letter at a time
how can i get that one letter to a char?
then from a char to an int?
don't use substring, you're overcomplicating the issue. The String class has a method called toCharArray(), which not surprisingly returns and array of chars which is exactly what you want. You can then loop through the array to get the various characters.
To turn a char into an int you have to cast it. Something like int myInt = (int)myChar.
If you cast it, wont that return the ascii value of the char? He may be asking for the numerical value, in which cause the command (i think) is:
Integer.parseInt()
well try them both and see which gives the result you want :)