string a="askdjfa;ldksfjwilgfj";
char[] c=a.ToCharArray();

解决方案 »

  1.   

    string a="d343";
        char[] aToArray=a.ToCharArray();
    Encoder enc=Encoding.Default.GetEncoder();
    byte[] b=new byte[10];
    enc.GetBytes(aToArray,0,aToArray.Length,b,0,false);
    foreach( byte c in b)
                 MessageBox.Show(Convert.ToString(c));
      

  2.   

    string temp = "this is a test";
    byte[] msg = Encoding.ASCII.GetBytes(temp);
      

  3.   

    byte[] msg = Encoding.ASCII.GetBytes(temp);
    或者:
    System.Convert.Tochar(string);
      

  4.   

    string temp = "this is a test";
    byte[] msg = System.Text.Encoding.ASCII.GetBytes(temp);
      

  5.   

    // 把十六进制字符串转换成字节型,返回字节型数组 
    public byte[] StringToByte(string InString) 
    {
    string[] ByteStrings;
    ByteStrings = InString.Split(" ".ToCharArray());
    byte[] ByteOut;
    ByteOut = new byte[ByteStrings.Length-1];
    for (int i = 0;i==ByteStrings.Length-1;i++) 
    {
    ByteOut[i] = Convert.ToByte(("0x" + ByteStrings[i]));

    return ByteOut;
    }
      

  6.   

    a="ddddddddddddddd";
    char[] b = a.ToCharArray();
      

  7.   

    string temp = "this is a test";
    byte[] msg = Encoding.ASCII.GetBytes(temp);这种方法可以
      

  8.   

    上面说的都对,但是只能对English.
    我给一个例子,汉字都可以的: string aa="哈阿";
    byte[] bt=new byte[0];
    UnicodeEncoding ue=new UnicodeEncoding();
    bt=ue.GetBytes(aa);
    Console.WriteLine(aa);

    string bb=ue.GetString(bt);
    Console.WriteLine(bb);