« WORD和ACCESS的数据交换域名的基础知识:域名解析, A记录, MX记录, CNAME记录, TTL »

asp utf-8转gb2312及urlencode函数

今天遇到自己上网拼命找资料了。无数个urlencode可以供使用,还可以找到很多版本的utf-8转gb的函数。但是都不是很好用。特别在遇到中文的时候。

下面的函数该是您收藏的。

<%
-----------------------------------
'utf-8 -> gb2312
'-----------------------------------
function UTF2GB(UTFStr)
UTFStr=replace(UTFStr,"+","%20")
for Dig=1 to len(UTFStr)
if mid(UTFStr,Dig,1)="%" then
if LCase(mid(UTFStr,Dig+1,1))="e" then
GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
Dig=Dig+8
else
GBStr=GBStr & chr(eval("&h"+mid(UTFStr,Dig+1,2)))
Dig=Dig+2
end if
else
GBStr=GBStr & mid(UTFStr,Dig,1)
end if
next
UTF2GB=GBStr
end function

function ConvChinese(x)
A=split(mid(x,2),"%")
i=0
j=0

for i=0 to ubound(A)
A(i)=c16to2(A(i))
next

for i=0 to ubound(A)-1
DigS=instr(A(i),"0")
Unicode=""
for j=1 to DigS-1
if j=1 then
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)
end if
next

if len(c2to16(Unicode))=4 then
ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode)))
else
ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode)))
end if
next
end function
function c2to16(x)
i=1
for i=1 to len(x) step 4
c2to16=c2to16 & hex(c2to10(mid(x,i,4)))
next '

原创文章如转载,请注明:转载自悠悠博客 [ http://www.ajaxstu.com/ ]

相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。