lixiang 发表于 2009-5-31 21:23:26

请问如何获取汉字内码?

比如:人(C8CB)生(C9FA)如(C8E7)梦(C3CE),怎样得到括号内的内码?

lynfr8 发表于 2009-5-31 22:07:13

#include <string.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#AutoIt3Wrapper_UseAnsi=y
$Form1 = GUICreate("汉字内码转换演示", 280, 113, 192, 124)
$Input1 = GUICtrlCreateInput("请输入汉字", 56, 16, 129, 21)
$Input2 = GUICtrlCreateInput("汉字内码结果", 56, 48, 129, 21)
$Label1 = GUICtrlCreateLabel("汉字", 8, 16, 36, 17)
$Label2 = GUICtrlCreateLabel("内码", 8, 48, 36, 17)
$Button = GUICtrlCreateButton("转换", 200, 24, 49, 33, 0)
$Label3 = GUICtrlCreateLabel("注意:必需编译之后才能正常运行", 54, 80, 184, 17)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
   Exit
      Case $Button
   $String = GUICtrlRead($Input1)
            $Hex = _StringToHex($String)
   GUICtrlSetData($Input2,$Hex)
EndSwitch
WEnd


切记:必需编译之后才能运行,否则只会显示内码的前两位而已
这是脚本编译方式的问题,必需要使用ANSI编译方式#AutoIt3Wrapper_UseAnsi=y

lynfr8 发表于 2009-5-31 22:08:33

_StringToHex
--------------------------------------------------------------------------------
Convert a string to a hex string.
#Include <String.au3>
_StringToHex($strChar)

lixiang 发表于 2009-5-31 22:17:37

呵呵,谢谢!刚刚已经找到最简单的办法了:

$bin = Binary("人生如梦")
$str = String($bin)
MsgBox(0,"人生如梦",$str)

lixiang 发表于 2009-5-31 22:19:39

不过好像一次只能转换两个汉字?

sensel 发表于 2009-6-1 01:31:17

补上汉字等量任意字符
页: [1]
查看完整版本: 请问如何获取汉字内码?