执行以下代码,读取包含中文字符串的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
|