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 参考
转成多字节编码吧,ascall只有一字节;
byte[] arr = new byte[] { }; arr = System.Text.Encoding.Default.GetBytes("胡锦涛访美"); StringBuilder strS = new StringBuilder(); foreach (byte s in arr) { strS.Append(s); }
你能把这个byte[]转为"我是中国人"吗?
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
参考
arr = System.Text.Encoding.Default.GetBytes("胡锦涛访美");
StringBuilder strS = new StringBuilder();
foreach (byte s in arr)
{
strS.Append(s);
}