java中ASCLL与字符串的互转

其实在java中,ascii码与字符串的互转,通过对int型和char型的强制转换就可以了

public class Change{

  //字符串转换为ascii
  public static String StringToA(String content){
    String result = "";
    int max = content.length();
    for (int i=0; i<max; i++){
      char c = content.charAt(i);
      int b = (int)c;
      result = result + b;
    }
    return result;
  }

  //ascii转换为string
  public static String AToString(int i){
    return Character.toString((char)i);
  }
  public static void main(String args[]){
    //请在终端运行
    System.out.println(StringToA(args[0]));
    System.out.println(AToString(new Integer(args[1])));
  }

 

posted @ 2013-08-23 10:08  popping  阅读(18031)  评论(0编辑  收藏  举报