最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > asp教程

ASP写的汉字转换UTF-8转GB2312技巧

日期:07-23    来源:中国设计秀    作者:cnwebshow.com

汉字转换为UTF-8p34中国设计秀

function chinese2unicode(Str) p34中国设计秀
  dim i p34中国设计秀
  dim Str_one p34中国设计秀
  dim Str_unicode p34中国设计秀
  for i=1 to len(Str) p34中国设计秀
    Str_one=Mid(Str,i,1) p34中国设计秀
    Str_unicode=Str_unicode&chr(38) p34中国设计秀
    Str_unicode=Str_unicode&chr(35) p34中国设计秀
    Str_unicode=Str_unicode&chr(120) p34中国设计秀
    Str_unicode=Str_unicode& Hex(ascw(Str_one)) p34中国设计秀
    Str_unicode=Str_unicode&chr(59) p34中国设计秀
  next p34中国设计秀
  Response.Write Str_unicode p34中国设计秀
end function    p34中国设计秀

p34中国设计秀
UTF-8 To GB2312p34中国设计秀

function UTF2GB(UTFStr)p34中国设计秀
    for Dig=1 to len(UTFStr)p34中国设计秀
        if mid(UTFStr,Dig,1)="%" thenp34中国设计秀
            if len(UTFStr) >= Dig+8 thenp34中国设计秀
                GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))p34中国设计秀
                Dig=Dig+8p34中国设计秀
            elsep34中国设计秀
                GBStr=GBStr & mid(UTFStr,Dig,1)p34中国设计秀
            end ifp34中国设计秀
        elsep34中国设计秀
            GBStr=GBStr & mid(UTFStr,Dig,1)p34中国设计秀
        end ifp34中国设计秀
    nextp34中国设计秀
    UTF2GB=GBStrp34中国设计秀
end functionp34中国设计秀

p34中国设计秀
function ConvChinese(x) p34中国设计秀
    A=split(mid(x,2),"%")p34中国设计秀
    i=0p34中国设计秀
    j=0p34中国设计秀
    p34中国设计秀
    for i=0 to ubound(A) p34中国设计秀
        A(i)=c16to2(A(i))p34中国设计秀
    nextp34中国设计秀
        p34中国设计秀
    for i=0 to ubound(A)-1p34中国设计秀
        DigS=instr(A(i),"0")p34中国设计秀
        Unicode=""p34中国设计秀
        for j=1 to DigS-1p34中国设计秀
            if j=1 then p34中国设计秀
                A(i)=right(A(i),len(A(i))-DigS)p34中国设计秀
                Unicode=Unicode & A(i)p34中国设计秀
            elsep34中国设计秀
                i=i+1p34中国设计秀
                A(i)=right(A(i),len(A(i))-2)p34中国设计秀
                Unicode=Unicode & A(i) p34中国设计秀
            end if p34中国设计秀
        nextp34中国设计秀
        p34中国设计秀
        if len(c2to16(Unicode))=4 thenp34中国设计秀
            ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode)))p34中国设计秀
        elsep34中国设计秀
            ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode)))p34中国设计秀
        end ifp34中国设计秀
    nextp34中国设计秀
end functionp34中国设计秀

function c2to16(x)p34中国设计秀
    i=1p34中国设计秀
    for i=1 to len(x)  step 4 p34中国设计秀
        c2to16=c2to16 & hex(c2to10(mid(x,i,4))) p34中国设计秀
    nextp34中国设计秀
end function p34中国设计秀
    p34中国设计秀
function c2to10(x)p34中国设计秀
    c2to10=0p34中国设计秀
    if x="0" then exit functionp34中国设计秀
    i=0p34中国设计秀
    for i= 0 to len(x) -1p34中国设计秀
        if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)p34中国设计秀
    next p34中国设计秀
end functionp34中国设计秀

function c16to2(x)p34中国设计秀
    i=0p34中国设计秀
    for i=1 to len(trim(x)) p34中国设计秀
        tempstr= c10to2(cint(int("&h" & mid(x,i,1))))p34中国设计秀
        do while len(tempstr)<4p34中国设计秀
        tempstr="0" & tempstrp34中国设计秀
        loopp34中国设计秀
        c16to2=c16to2 & tempstrp34中国设计秀
    nextp34中国设计秀
end functionp34中国设计秀

function c10to2(x)p34中国设计秀
    mysign=sgn(x)p34中国设计秀
    x=abs(x)p34中国设计秀
    DigS=1p34中国设计秀
    do p34中国设计秀
        if x<2^DigS thenp34中国设计秀
            exit dop34中国设计秀
        elsep34中国设计秀
            DigS=DigS+1p34中国设计秀
        end ifp34中国设计秀
    loopp34中国设计秀
    tempnum=xp34中国设计秀
    p34中国设计秀
    i=0p34中国设计秀
    for i=DigS to 1 step-1p34中国设计秀
        if tempnum>=2^(i-1) thenp34中国设计秀
            tempnum=tempnum-2^(i-1)p34中国设计秀
            c10to2=c10to2 & "1"   p34中国设计秀
        elsep34中国设计秀
            c10to2=c10to2 & "0"p34中国设计秀
        end ifp34中国设计秀
    nextp34中国设计秀
    if mysign=-1 then c10to2="-" & c10to2p34中国设计秀
end functionp34中国设计秀

本文引用地址:/bc/article_46255.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明