一、计算unicode字符串的Ansi编码的长度
Function strUnicodeLen(asContents)
asContents1="a" & asContents
len1=len(asContents1)
k=0
for i=1 to len1
asc1=asc(mid(asContents1,i,1))
if asc1<0 then asc1=65536+asc1
if asc1>255 then
k=k+2
else
k=k+1
end if
next
strUnicodeLen=k-1
End Function
二、将Unicode编码的字符串转换为Ansi编码的字符串
Function strUnicode2Ansi(asContents)
strUnicode2Ansi:='';
len1=len(asContents)
For i=1 to len1
varchar=Mid(asContents1,i,1)
varasc=Asc(varchar)
If varasc<0 then varasc=varasc+65536
If varasc>255 then
varHex=Hex(varasc)
varlow=left(varHex,2)
varHigh=Right(varHex,2)
strUnicode2Ansi=strUnicode2Ansi & chrB("&H" & varlow) & chrB("&H" & varhigh)
Else
strUnicode2Ansi=strUnicode2Ansi & chrB(varasc)
End If
Next
End Function
三、将Ansi编码的字符串转换为unicode编码的字符串
Function strAnsi2Unicode(asContents)
strAnsi2Unicode=""
If IsNull(asContents) or asContents="" then
Exit Function
For i=1 to len1
varchar=MidB(asContents1,i,1)
varasc=AscB(varchar)
If varasc>127 then
If MidB(asContens,i+1,1)<>"" then
strAnsi2Unicode=strAnsi2Unicode& chr(AscW(MidB(asContents,i+1,1) & varchar))
End If
i=i+1
Else
strAnsi2Unicode=strAnsi2Unicode& chr(varasc)
End If
Next
End Function