手机
当前位置:查字典教程网 >编程开发 >ASP教程 >UTF-8转GB2312函数
UTF-8转GB2312函数
摘要:复制代码代码如下:

复制代码 代码如下:<%

'用途:將UTF-8編碼漢字轉換為GB2312碼,兼容英文和數字

'版權:雖說是原創,其實也參考了別人的部分算法

'用法:Response.writeUTF2GB("%E9%83%BD%E5%B8%82%E6%83%85%E7%B7%A3%E6%98%9F%E5%BA%A7")

functionUTF2GB(UTFStr)

forDig=1tolen(UTFStr)

ifmid(UTFStr,Dig,1)="%"then

iflen(UTFStr)>=Dig+8then

GBStr=GBStr&ConvChinese(mid(UTFStr,Dig,9))

Dig=Dig+8

else

GBStr=GBStr&mid(UTFStr,Dig,1)

endif

else

GBStr=GBStr&mid(UTFStr,Dig,1)

endif

next

UTF2GB=GBStr

endfunction

functionConvChinese(x)

A=split(mid(x,2),"%")

i=0

j=0

fori=0toubound(A)

A(i)=c16to2(A(i))

next

fori=0toubound(A)-1

DigS=instr(A(i),"0")

Unicode=""

forj=1toDigS-1

ifj=1then

A(i)=right(A(i),len(A(i))-DigS)

Unicode=Unicode&A(i)

else

i=i+1

A(i)=right(A(i),len(A(i))-2)

Unicode=Unicode&A(i)

endif

next

iflen(c2to16(Unicode))=4then

ConvChinese=ConvChinese&chrw(int("&H"&c2to16(Unicode)))

else

ConvChinese=ConvChinese&chr(int("&H"&c2to16(Unicode)))

endif

next

endfunction

functionc2to16(x)

i=1

fori=1tolen(x)step4

c2to16=c2to16&hex(c2to10(mid(x,i,4)))

next

endfunction

functionc2to10(x)

c2to10=0

ifx="0"thenexitfunction

i=0

fori=0tolen(x)-1

ifmid(x,len(x)-i,1)="1"thenc2to10=c2to10+2^(i)

next

endfunction

functionc16to2(x)

i=0

fori=1tolen(trim(x))

tempstr=c10to2(cint(int("&h"&mid(x,i,1))))

dowhilelen(tempstr)<4

tempstr="0"&tempstr

loop

c16to2=c16to2&tempstr

next

endfunction

functionc10to2(x)

mysign=sgn(x)

x=abs(x)

DigS=1

do

ifx<2^DigSthen

exitdo

else

DigS=DigS+1

endif

loop

tempnum=x

i=0

fori=DigSto1step-1

iftempnum>=2^(i-1)then

tempnum=tempnum-2^(i-1)

c10to2=c10to2&"1"

else

c10to2=c10to2&"0"

endif

next

ifmysign=-1thenc10to2="-"&c10to2

endfunction

%>

【UTF-8转GB2312函数】相关文章:

php实现utf-8和GB2312编码相互转换函数代码

pjblog实现类似CMS的首页调用

用XML+FSO+JS实现服务器端文件的选择效果

[ASP]GetRows的用法详解

计算两个时间之差的函数

利用FSO取得BMP,JPG,PNG,GIF文件信息

直接保存URL图像或网页到服务器本地的类

用存储过程、GetRows()、抽取10万条数据的速度测试

[转]ASP常用函数:TimeZone

javascript asp教程第十一课--Application 对象

精品推荐
分类导航