转换中文为unicode 转换unicode到正常文本

2018-09-06 12:12

阅读:468

  复制代码 代码如下:
//转换中文为unicode
functionURLEncoding(vstrIn)

dimi
dimstrReturn,ThisChr,innerCode,Hight8,Low8

strReturn=
fori=1toLen(vstrIn)
ThisChr=Mid(vStrIn,i,1)
IfAbs(Asc(ThisChr))<&HFFthen
strReturn=strReturn&ThisChr
else
innerCode=Asc(ThisChr)
IfinnerCode<0then
innerCode=innerCode+&H10000
endIf
Hight8=(innerCodeand&HFF00)\&HFF
Low8=innerCodeand&HFF
strReturn=strReturn&%&Hex(Hight8)&%&Hex(Low8)
endIf
next

URLEncoding=strReturn

endfunction

//转换unicode到正常文本
functionbytes2BSTR(vIn)
dimi
dimstrReturn,ThisCharCode,nextCharCode

strReturn=
fori=1toLenB(vIn)
ThisCharCode=AscB(MidB(vIn,i,1))
IfThisCharCode<&H80then
strReturn=strReturn&Chr(ThisCharCode)
else
nextCharCode=AscB(MidB(vIn,i+1,1))
strReturn=strReturn&Chr(CLng(ThisCharCode)*&H100+CInt(nextCharCode))
i=i+1
endIf
next
bytes2BSTR=strReturn

endfunction

functiongetText(o,url)

dimoReq

onerrorresumenext

ifoisnothingthen
//创建XMLHTTP对象
setoReq=CreateObject(MSXML2.XMLHTTP)
else
setoReq=o
endif

oReq.openget,url,false
oReq.send

ifoReq.status=200oroReq.status=0then
getText=bytes2BSTR(oReq.responseBody)
else
getText=
endif

endfunction


评论


亲,登录后才可以留言!