|
本帖最后由 txm 于 2012-6-14 09:05 编辑
执行以下代码,读取包含中文字符串的AU3文件.
另存为新文件后,代码迷惑,编译.
只对简单的中文字符串处理,请大家多提供点不同形态的字符串.
$file = FileOpenDialog("GBK2Bin", @ScriptDir, "Au3 File(*.au3)")
If @error Then Exit
$SoureCode = FileRead($file)
$NeedChange = StringRegExp($SoureCode, '["' & "'].*?[\x{4e00}-\x{9fa5}]+.*?[" & '"' & "']", 3)
For $i = 0 To UBound($NeedChange) - 1
$Bin = StringToBinary(StringRegExpReplace($NeedChange[$i], '^["' & "'](.*?[\x{4e00}-\x{9fa5}]+.*?)[" & '"' & "']$", "$1"))
$SoureCode = StringReplace($SoureCode, $NeedChange[$i], "BinaryToString('" & $Bin & "')", 1, 1)
Next
Local $var = FileSaveDialog("另存为.", @ScriptDir, "AU3脚本 (*.au3)", 2)
If Not @error Then
If Not StringRegExp($var, '.+\.au3$', 0) Then $var = $var & ".au3"
$fileopen = FileOpen($var, 2)
FileWrite($fileopen, $SoureCode)
EndIf
_GUICtrlEdit_AppendText($Edit9, @YEAR & "-" & @MON & "-" & @MDAY & $tecs & " " & "测试文本" & @CRLF)
转换后:
_GUICtrlEdit_AppendText($Edit9, @YEAR & BinaryToString('0x2D22202620404D4F4E202620222D22202620404D444159202620247465637320262022202220262022B2E2CAD4CEC4B1BE') & @CRLF)
一些宏也被转换了,真正要转换的就只有“测试文本”几个字就可以了,还望修正,谢谢! |
评分
-
查看全部评分
|