源码论坛,商业源码下载,尽在锦尚中国商业源码论坛

标题: 转换中文为unicode 转换unicode到正常文本 [打印本页]

作者: 欧阳锋    时间: 2019-2-13 01:05
标题: 转换中文为unicode 转换unicode到正常文本
  1. '//转换中文为unicode
  2. function URLEncoding(vstrIn)

  3.     dim i
  4.     dim strReturn,ThisChr,innerCode,Hight8,Low8

  5.     strReturn = ""
  6.     for i = 1 to Len(vstrIn)
  7.         ThisChr = Mid(vStrIn,i,1)
  8.         If Abs(Asc(ThisChr)) < &HFF then
  9.             strReturn = strReturn & ThisChr
  10.         else
  11.             innerCode = Asc(ThisChr)
  12.             If innerCode < 0 then
  13.                 innerCode = innerCode + &H10000
  14.             end If
  15.             Hight8 = (innerCode  and &HFF00)\ &HFF
  16.             Low8 = innerCode and &HFF
  17.             strReturn = strReturn & "%" & Hex(Hight8) &  "%" & Hex(Low8)
  18.         end If
  19.     next

  20.     URLEncoding = strReturn

  21. end function

  22. '//转换unicode到正常文本
  23. function bytes2BSTR(vIn)
  24.     dim i
  25.     dim strReturn,ThisCharCode,nextCharCode

  26.     strReturn = ""
  27.     for i = 1 to LenB(vIn)
  28.         ThisCharCode = AscB(MidB(vIn,i,1))
  29.         If ThisCharCode < &H80 then
  30.             strReturn = strReturn & Chr(ThisCharCode)
  31.         else
  32.             nextCharCode = AscB(MidB(vIn,i+1,1))
  33.             strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(nextCharCode))
  34.             i = i + 1
  35.         end If
  36.     next
  37.     bytes2BSTR = strReturn

  38. end function

  39. function getText(oReq,url)

  40.     on error resume next
  41.     '//创建XMLHTTP对象     
  42.     if oReq is nothing then
  43.         set oReq    = CreateObject("MSXML2.XMLHTTP")
  44.     end if

  45.     if    not oReq is nothing then
  46.         oReq.open "get",url,false
  47.         oReq.send  

  48.         if oReq.status = 200 then
  49.             getText = bytes2BSTR(oReq.responseBody)
  50.         else
  51.             getText = ""
  52.         end if
  53.     else
  54.         getText = ""
  55.     end if

  56. end function
复制代码





欢迎光临 源码论坛,商业源码下载,尽在锦尚中国商业源码论坛 (https://bbs.52jscn.com/) Powered by Discuz! X3.3