当前位置: 移动技术网 > IT编程>开发语言>Asp > 转换中文为unicode 转换unicode到正常文本

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

复制代码 代码如下:

'//转换中文为unicode
function urlencoding(vstrin)

    dim i
    dim strreturn,thischr,innercode,hight8,low8

    strreturn = ""
    for i = 1 to len(vstrin)
        thischr = mid(vstrin,i,1)
        if abs(asc(thischr)) < &hff then
            strreturn = strreturn & thischr
        else
            innercode = asc(thischr)
            if innercode < 0 then
                innercode = innercode + &h10000
            end if
            hight8 = (innercode  and &hff00)\ &hff
            low8 = innercode and &hff
            strreturn = strreturn & "%" & hex(hight8) &  "%" & hex(low8)
        end if
    next

    urlencoding = strreturn

end function

'//转换unicode到正常文本
function bytes2bstr(vin)
    dim i
    dim strreturn,thischarcode,nextcharcode

    strreturn = ""
    for i = 1 to lenb(vin)
        thischarcode = ascb(midb(vin,i,1))
        if thischarcode < &h80 then
            strreturn = strreturn & chr(thischarcode)
        else
            nextcharcode = ascb(midb(vin,i+1,1))
            strreturn = strreturn & chr(clng(thischarcode) * &h100 + cint(nextcharcode))
            i = i + 1
        end if
    next
    bytes2bstr = strreturn

end function

function gettext(o,url)

    dim oreq

    on error resume next

    if o is nothing then
        '//创建xmlhttp对象
        set oreq    = createobject("msxml2.xmlhttp")
    else
        set oreq    = o 
    end if

        oreq.open "get",url,false
        oreq.send 

    if oreq.status = 200 or oreq.status = 0 then    
        gettext = bytes2bstr(oreq.responsebody)
    else
        gettext = ""
    end if

end function

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网