yueyun
asked on
Convert a String to Ascii code
What is the method used to convert a String to Ascii code?
Typically the individual elements of a string are already in ASCII code. To view the codes, try printing each element as an integer instead of a character.
From what code do you want to convert the string? EBCDIC to ASCII? What tools do you have available with which to perform the conversion?
ASKER
I'm sorry that i have wrongly placed my question, it should be under java programming.
However, i have tried it but there is an error because JDK cannot convert a String to int while compiling. My souce code is :
public class ascii{
public static void main(String args[]){
byte[] asciiVal={0x61};
String asciia=new String(asciiVal);
System.out.println(asciia) ;
System.out.println((int)as ciia);
}
}
The first print method will print the character a, the second should print the ascii code for 'a'.
However, i have tried it but there is an error because JDK cannot convert a String to int while compiling. My souce code is :
public class ascii{
public static void main(String args[]){
byte[] asciiVal={0x61};
String asciia=new String(asciiVal);
System.out.println(asciia)
System.out.println((int)as
}
}
The first print method will print the character a, the second should print the ascii code for 'a'.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.