Link to home
Start Free TrialLog in
Avatar of yueyun
yueyun

asked on

Convert a String to Ascii code

What is the method used to convert a String to Ascii code?
Avatar of s_turner99
s_turner99

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.
Avatar of ozo
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?
Avatar of yueyun

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)asciia);
  }
}
The first print method will print the character a, the second should print the ascii code for 'a'.
ASKER CERTIFIED SOLUTION
Avatar of _lychee_
_lychee_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial