找回密码
 加入
搜索
查看: 2058|回复: 1

在unicode编译脚本情况下的一个难题

[复制链接]
发表于 2008-5-21 23:15:52 | 显示全部楼层 |阅读模式
在AUTOIT脚本编程中,可以使用“#AutoIt3Wrapper_UseAnsi=y”对脚本进行ANSI模式编译,这样在使用STRINGLEN,STRINGLEFT,STRINGMID,STRINGRIGHT,STRINGFORMAT等字符串操作函数时都会将一个汉字看作两个字符;但是现在由于需要对AUTOIT脚本按照UNICODE的模式进行编译,这样导致在使用上述字符串操作函数时都将一个汉字看作一个字符。我的问题是,如何在UNICODE编译的情况下使用字符串操作函数时会将一个汉字看作两个字符呢?


#AutoIt3Wrapper_UseAnsi=y
msgbox(0, "test", stringlen("中国人")) ;output 6



#AutoIt3Wrapper_UseAnsi=n
msgbox(0, "test", stringlen("中国人")) ;output 3


[ 本帖最后由 firewzy 于 2008-5-23 00:55 编辑 ]
 楼主| 发表于 2008-5-23 00:55:13 | 显示全部楼层
已解决

#AutoIt3Wrapper_UseAnsi=n

$Str_Field = "嘿嘿haha"
$Int_FieldLength = StringLen($Str_Field)
$Int_FieldCnCharCount = 0

For $Int_FieldStrIndex = 1 To $Int_FieldLength

        If Not StringIsASCII(StringMid($Str_Field, $Int_FieldStrIndex, 1)) Then 
                $Int_FieldCnCharCount  += 2
        Else
                $Int_FieldCnCharCount += 1
        EndIf

Next

Msgbox(0, "test", $Int_FieldCnCharCount)  ; output 8


得到的$Int_FieldCnCharCount就是中英文混合字符串的ANSI长度。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-17 18:58 , Processed in 0.075003 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表