UTF-8轉(zhuǎn)GB2312函數(shù)
更新時(shí)間:2006年09月23日 00:00:00 作者:
復(fù)制代碼 代碼如下:
<%
'用途:將UTF-8編碼漢字轉(zhuǎn)換為GB2312碼,兼容英文和數(shù)字
'版權(quán):雖說是原創(chuàng),其實(shí)也參考了別人的部分算法
'用法:Response.write UTF2GB("%E9%83%BD%E5%B8%82%E6%83%85%E7%B7%A3 %E6%98%9F%E5%BA%A7")
function UTF2GB(UTFStr)
for Dig=1 to len(UTFStr)
if mid(UTFStr,Dig,1)="%" then
if len(UTFStr) >= Dig+8 then
GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
Dig=Dig+8
else
GBStr=GBStr & mid(UTFStr,Dig,1)
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
end function
function c2to10(x)
c2to10=0
if x="0" then exit function
i=0
for i= 0 to len(x) -1
if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
next
end function
function c16to2(x)
i=0
for i=1 to len(trim(x))
tempstr= c10to2(cint(int("&h" & mid(x,i,1))))
do while len(tempstr)<4
tempstr="0" & tempstr
loop
c16to2=c16to2 & tempstr
next
end function
function c10to2(x)
mysign=sgn(x)
x=abs(x)
DigS=1
do
if x<2^DigS then
exit do
else
DigS=DigS+1
end if
loop
tempnum=x
i=0
for i=DigS to 1 step-1
if tempnum>=2^(i-1) then
tempnum=tempnum-2^(i-1)
c10to2=c10to2 & "1"
else
c10to2=c10to2 & "0"
end if
next
if mysign=-1 then c10to2="-" & c10to2
end function
%>
'用途:將UTF-8編碼漢字轉(zhuǎn)換為GB2312碼,兼容英文和數(shù)字
'版權(quán):雖說是原創(chuàng),其實(shí)也參考了別人的部分算法
'用法:Response.write UTF2GB("%E9%83%BD%E5%B8%82%E6%83%85%E7%B7%A3 %E6%98%9F%E5%BA%A7")
function UTF2GB(UTFStr)
for Dig=1 to len(UTFStr)
if mid(UTFStr,Dig,1)="%" then
if len(UTFStr) >= Dig+8 then
GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
Dig=Dig+8
else
GBStr=GBStr & mid(UTFStr,Dig,1)
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
end function
function c2to10(x)
c2to10=0
if x="0" then exit function
i=0
for i= 0 to len(x) -1
if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
next
end function
function c16to2(x)
i=0
for i=1 to len(trim(x))
tempstr= c10to2(cint(int("&h" & mid(x,i,1))))
do while len(tempstr)<4
tempstr="0" & tempstr
loop
c16to2=c16to2 & tempstr
next
end function
function c10to2(x)
mysign=sgn(x)
x=abs(x)
DigS=1
do
if x<2^DigS then
exit do
else
DigS=DigS+1
end if
loop
tempnum=x
i=0
for i=DigS to 1 step-1
if tempnum>=2^(i-1) then
tempnum=tempnum-2^(i-1)
c10to2=c10to2 & "1"
else
c10to2=c10to2 & "0"
end if
next
if mysign=-1 then c10to2="-" & c10to2
end function
%>
您可能感興趣的文章:
- 將字符串轉(zhuǎn)換成gb2312或者utf-8編碼的參數(shù)(js版)
- php實(shí)現(xiàn)utf-8和GB2312編碼相互轉(zhuǎn)換函數(shù)代碼
- UTF-8 GBK UTF8 GB2312 之間的區(qū)別和關(guān)系介紹
- PHP字符編碼問題之GB2312 VS UTF-8解決方法
- VBS實(shí)現(xiàn)GB2312,UTF-8,Unicode,BIG5編碼轉(zhuǎn)換工具
- PHP 解決utf-8和gb2312編碼轉(zhuǎn)換問題
- unicode utf-8 gb18030 gb2312 gbk各種編碼對(duì)比
- ASP中Utf-8與Gb2312編碼轉(zhuǎn)換亂碼問題的解決方法 頁面編碼聲明
- MSSQL轉(zhuǎn)MYSQL,gb2312轉(zhuǎn)utf-8無亂碼解決方法
- PHP iconv 解決utf-8和gb2312編碼轉(zhuǎn)換問題
- ASP UTF-8頁面亂碼+GB2312轉(zhuǎn)UTF-8 +生成UTF-8格式的文件(編碼)
- 用VBS實(shí)現(xiàn)的批量gb2312轉(zhuǎn)utf-8,支持拖動(dòng)
- 用javascript實(shí)現(xiàn)gb2312轉(zhuǎn)utf-8的腳本
- [轉(zhuǎn)]ASP實(shí)現(xiàn)關(guān)鍵詞獲取(各搜索引擎,GB2312及UTF-8)
- utf-8編碼轉(zhuǎn)換成gb2312
- 將編碼從GB2312轉(zhuǎn)成UTF-8的方法匯總(從前臺(tái)、程序、數(shù)據(jù)庫)
相關(guān)文章
自己寫的文件操作的function和Sub vb.net dll
自己寫的文件操作的function和Sub vb.net dll...2007-08-08asp教程中g(shù)et post提交表單有5點(diǎn)區(qū)別
asp教程中g(shù)et post提交表單有5點(diǎn)區(qū)別分別以HTTP請(qǐng)求,表單兩者分別介紹,需要的朋友可以了解下2012-12-12asp動(dòng)態(tài)級(jí)聯(lián)菜單代碼
asp動(dòng)態(tài)級(jí)聯(lián)菜單代碼...2007-03-03asp自動(dòng)補(bǔ)全html標(biāo)簽自動(dòng)閉合(正則表達(dá)式)
asp自動(dòng)補(bǔ)全html標(biāo)簽自動(dòng)閉合,方便asp截取帶有html標(biāo)簽的內(nèi)容,防止頁面變形2012-10-10.Net 自定義轉(zhuǎn)換器JsonConverter的使用詳解
這篇文章主要介紹了.Net 自定義轉(zhuǎn)換器JsonConverter的使用,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-04-04