比如现在我有这么一个字符串 “helloWorld!”
转换成ascii是1041011081081118711111410810033  
 
那么如果我现在等到的是  
1041011081081118711111410810033  
并知道该字符串有11个字节  
问:我如何才能从上面的ascii码中获取到“helloWorld!”

解决方案 »

  1.   

    因为你生成的字符的ASCII字符串有三位的也有两位的,最后可能不能区别出该怎么分析最后的字符串而成了“死”的数据,你生成ASCII字符串的时候最好保证每个字符的ASCII字符串保持一致,比如都是3位,或都是4位。因为你这里使用的都是小于127的字符,所以使用3位足够了,可以参考下面的代码:private void button3_Click(object sender, EventArgs e)
    {
    string tt = "helloWord!";
    for (int i = 0; i < tt.Length; i++)

    //这里保证每个字符都使用3个数字
    Console.Write(((int)tt[i]).ToString("000"));
    }
    //最后生成的字符串,这和楼主原来的是不一样的。
    string str = "104101108108111087111114100033"; string hello = null;
    //这里按固定位数分析字符串以还原原来的字符串内容
    for (int i = 0; i < str.Length / 3; i++)
    {
    int ci = int.Parse(str.Substring(i * 3, 3));
    hello += ((char)ci).ToString();
    }
    Console.WriteLine(hello);
    }
      

  2.   

    System::Convert::ToSingle(char) 
    ToInt16() 
    ToInt32() 
    ToInt64() 
    前冇都加System::Convert:: 
    都可以,呵呵 例 
    char^ a; 
    a='a'; 
    this->label1->Text=System::Convert::ToInt16(a).ToString(); 
    那麽lable1->Text结果为97
      

  3.   

    hbxtlhx(平民百姓-自已动手,丰衣足食)说得对