haodd 发表于 2011-9-13 19:01:03

字符串 16进制 互相转换的问题 乱码了

字符串 16进制 互相转换的问题雪花
\uD1A9\uBBA8
??
e+>19:00:19 AutoIT
---------------------------
雪花
---------------------------
\uD1A9\uBBA8

톩뮨


---------------------------
确定   
---------------------------


#include<string.au3>
Func stringtoHex($Hex)
Local $b = ''
$Hex = StringRegExp($Hex,"(.?)",3)
For$i = 0 To UBound($Hex) - 2
      $b &= "\u"& _StringToHex($Hex[$i])
Next
        Return $b
EndFunc

Func Hextostring($string)
    Local $temp_str,$temp_s
    $temp_s=StringSplit($string,'\u',3)
        $string=''       
    For $n=0 To UBound($temp_s)-1
      If StringLen($temp_s[$n])>4 Then
            $temp_s[$n]=ChrW('0x'&StringMid($temp_s[$n],1,4))&StringMid($temp_s[$n],5)
            $string&=$temp_s[$n]
      ElseIf StringLen($temp_s[$n])<4 Then
            $string&=$temp_s[$n]
      Else               
      $temp_s[$n]=ChrW('0x'&$temp_s[$n])
      $string&=$temp_s[$n]
      EndIf
    Next
    Return $string
EndFunc

ConsoleWrite(Hextostring("\u96EA\u82B1")&@CRLF)
ConsoleWrite(stringtoHex(Hextostring("\u96EA\u82B1"))&@CRLF)
ConsoleWrite(Hextostring(stringtoHex(Hextostring("\u96EA\u82B1")))&@CRLF)

MsgBox(0,Hextostring("\u96EA\u82B1"),stringtoHex(Hextostring("\u96EA\u82B1"))&@CRLF&Hextostring(stringtoHex(Hextostring("\u96EA\u82B1")))&@CRLF)

页: [1]
查看完整版本: 字符串 16进制 互相转换的问题 乱码了