需要处理 串口通信  用 Text Model  发送  但是 怎么把汉字转化成 ACSII

解决方案 »

  1.   

    byte[] buff = System.Text.Encoding.ASCII.GetBytes("我是中国人");
      

  2.   

    汉字绝对不能转换为ASCII码,只能转换为ANSI码...System.Text.Encoding.Default.GetBytes("我是中国人")orSystem.Text.Encoding.GetEncoding("GB2312").GetBytes("我是中国人")
      

  3.   


    你能把这个byte[]转为"我是中国人"吗?
      

  4.   

    byte[] buff = System.Text.Encoding.Default.GetBytes("我是中国人");不好意思,我写错了。
      

  5.   

    string tempstr [] = System.Text.Encoding.Default.GetString(buff);
      

  6.   

     汉字没办法转成asc吗,建议用 UTF-8编码
      

  7.   

    汉字占两字节,,ACSII是一个字节,怎么转啊使用其它两字节可用的编码
      

  8.   

    Public Function AsciiToHex(strChinese As String) As String                '汉字转16进制ASCII 
          Dim iLen    As Long 
          iLen = Len(strChinese) 
          Dim tmpByte()    As Byte 
          Dim iNext    As Long    
            Dim iTmp    As Integer 
            Dim strTmp    As String 
            For iNext = 1 To iLen 
                  iTmp = Abs(Asc(Mid(strChinese, iNext, 1))) 
                  If iTmp > 127 Then                      
                      tmpByte = StrConv(Mid(strChinese, iNext, 1), vbFromUnicode) 
                      strTmp = strTmp & Hex(tmpByte(0)) 
                      strTmp = strTmp & Hex(tmpByte(1)) 
                  Else 
                    strTmp = strTmp & Hex(iTmp) 
                  End If 
            Next 
            AsciiToHex = strTmp 
      End Function
    参考
      

  9.   

    转成多字节编码吧,ascall只有一字节;
      

  10.   

     byte[] arr = new byte[] { };
                arr = System.Text.Encoding.Default.GetBytes("胡锦涛访美");
                StringBuilder strS = new StringBuilder();
                foreach (byte s in arr)
                {
                    strS.Append(s);
                }
      

  11.   

    结贴  大多数手机 不支持  AT  TextModel 解码 还是用  PDU  吧