更多相关内容...>>ASP字符转换:UTF-8与GB2312互转
ASP字符转换:UTF-8与GB2312互转
UTF-8转GB2312函数
b2rV15 http://blog.numino.net/
<%
fhqrvy http://blog.numino.net/
'用途:將UTF-8編碼漢字轉換為GB2312碼,兼容英文和數字
yO6v75 http://blog.numino.net/
'版權:雖說是原創,其實也參考了別人的部分算法
i0h4Cd http://blog.numino.net/
'用法:Response.write UTF2GB("%E9%83%BD%E5%B8%82%E6%83%85%E7%B7%A3 %E6%98%9F%E5%BA%A7")
R7B1mR http://blog.numino.net/
function UTF2GB(UTFStr)
T260nn http://blog.numino.net/
for Dig=1 to len(UTFStr)
vfC86S http://blog.numino.net/
if mid(UTFStr,Dig,1)="%" then
PcXNvm http://blog.numino.net/
if len(UTFStr) >= Dig+8 then
O5xrEa http://blog.numino.net/
GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
vNIp6o http://blog.numino.net/
Dig=Dig+8
UdQCuT http://blog.numino.net/
else
J0o99a http://blog.numino.net/
GBStr=GBStr & mid(UTFStr,Dig,1)
7YpIwr http://blog.numino.net/
end if
bflbQj http://blog.numino.net/
else
Um0Npj http://blog.numino.net/
GBStr=GBStr & mid(UTFStr,Dig,1)
ykCH2D http://blog.numino.net/
end if
4MztnT http://blog.numino.net/
next
wFx7Xo http://blog.numino.net/
UTF2GB=GBStr
g8vwNN http://blog.numino.net/
end function
lY96h2 http://blog.numino.net/
function ConvChinese(x)
BckDw4 http://blog.numino.net/
A=split(mid(x,2),"%")
4rcyaf http://blog.numino.net/
i=0
n669OL http://blog.numino.net/
j=0
WZG8i7 http://blog.numino.net/
for i=0 to ubound(A)
hCTcHu http://blog.numino.net/
A(i)=c16to2(A(i))
P43Gyl http://blog.numino.net/
next
QY5tBm http://blog.numino.net/
for i=0 to ubound(A)-1
pgsz4M http://blog.numino.net/
DigS=instr(A(i),"0")
N8EJ05 http://blog.numino.net/
Unicode=""
QE6Xkk http://blog.numino.net/
for j=1 to DigS-1
2mMaI2 http://blog.numino.net/
if j=1 then
uGt44v http://blog.numino.net/
A(i)=right(A(i),len(A(i))-DigS)
mp6XX9 http://blog.numino.net/
Unicode=Unicode & A(i)
hi2ECZ http://blog.numino.net/
else
FdPM89 http://blog.numino.net/
i=i+1
X45hwU http://blog.numino.net/
A(i)=right(A(i),len(A(i))-2)
Uopt2U http://blog.numino.net/
Unicode=Unicode & A(i)
2hRKLr http://blog.numino.net/
end if
5hfDZi http://blog.numino.net/
next
729mdF http://blog.numino.net/
if len(c2to16(Unicode))=4 then
DMK06B http://blog.numino.net/
ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode)))
uP3Cj6 http://blog.numino.net/
else
oO8tPZ http://blog.numino.net/
ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode)))
DKJ8hj http://blog.numino.net/
end if
F2iZAA http://blog.numino.net/
next
l73Hca http://blog.numino.net/
end function
9wjhIh http://blog.numino.net/
function c2to16(x)
5or2Nx http://blog.numino.net/
i=1
iq4NDh http://blog.numino.net/
for i=1 to len(x) step 4
im995q http://blog.numino.net/
c2to16=c2to16 & hex(c2to10(mid(x,i,4)))
R8T93l http://blog.numino.net/
next
2HGAJm http://blog.numino.net/
end function
0GffzE http://blog.numino.net/
function c2to10(x)
5IR7eC http://blog.numino.net/
c2to10=0
62aZag http://blog.numino.net/
if x="0" then exit function
JLr0K5 http://blog.numino.net/
i=0
apdH0j http://blog.numino.net/
for i= 0 to len(x) -1
tvd4e2 http://blog.numino.net/
if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
CQdURV http://blog.numino.net/
next
0xNK0s http://blog.numino.net/
end function
CLypAL http://blog.numino.net/
function c16to2(x)
N8cBE2 http://blog.numino.net/
i=0
2TEAMD http://blog.numino.net/
for i=1 to len(trim(x))
010fGH http://blog.numino.net/
tempstr= c10to2(cint(int("&h" & mid(x,i,1))))
s8eU45 http://blog.numino.net/
do while len(tempstr)<4
M4lYQ9 http://blog.numino.net/
tempstr="0" & tempstr
orxb3u http://blog.numino.net/
loop
xy0NGR http://blog.numino.net/
c16to2=c16to2 & tempstr
8YGt1s http://blog.numino.net/
next
7r6kHE http://blog.numino.net/
end function
LOdSzH http://blog.numino.net/
function c10to2(x)
zwK09n http://blog.numino.net/
mysign=sgn(x)
Dk1gdJ http://blog.numino.net/
x=abs(x)
ZF5bZG http://blog.numino.net/
DigS=1
yC0I9T http://blog.numino.net/
do
G6aI1k http://blog.numino.net/
if x<2^DigS then
6mpsHS http://blog.numino.net/
exit do
0JrKCn http://blog.numino.net/
else
vOFfbs http://blog.numino.net/
DigS=DigS+1
4sayHF http://blog.numino.net/
end if
A6wFN1 http://blog.numino.net/
loop
UBdDeb http://blog.numino.net/
tempnum=x
LW0yp2 http://blog.numino.net/
i=0
j5lD3t http://blog.numino.net/
for i=DigS to 1 step-1
35n4NR http://blog.numino.net/
if tempnum>=2^(i-1) then
f4Q8tz http://blog.numino.net/
tempnum=tempnum-2^(i-1)
Nif135 http://blog.numino.net/
c10to2=c10to2 & "1"
cJspy1 http://blog.numino.net/
else
SWOIsC http://blog.numino.net/
c10to2=c10to2 & "0"
GWMpcn http://blog.numino.net/
end if
W660Wg http://blog.numino.net/
next
01kgof http://blog.numino.net/
if mysign=-1 then c10to2="-" & c10to2
G8y7K0 http://blog.numino.net/
end function
Z6Aa8g http://blog.numino.net/
%>
nHukHr http://blog.numino.net/
-----------------------------------------------------------------------------------------------------------------------------
z1Oq32 http://blog.numino.net/
ASP编码转换函数GB2312转换UTF-8
tgALv1 http://blog.numino.net/
<%
nJ2gjY http://blog.numino.net/
Function chinese2unicode(Str)
cDOyeo http://blog.numino.net/
dim i
Wcxjuz http://blog.numino.net/
dim Str_one
6N3876 http://blog.numino.net/
dim Str_unicode
hCH0i7 http://blog.numino.net/
For i=1 to len(Str)
WC51zB http://blog.numino.net/
Str_one=Mid(Str,i,1)
OQm4az http://blog.numino.net/
Str_unicode=Str_unicode&chr(38)
5PjC5w http://blog.numino.net/
Str_unicode=Str_unicode&chr(35)
RkcXTr http://blog.numino.net/
Str_unicode=Str_unicode&chr(120)
FlKg35 http://blog.numino.net/
Str_unicode=Str_unicode& Hex(ascw(Str_one))
9CUvZd http://blog.numino.net/
Str_unicode=Str_unicode&chr(59)
SzGif9 http://blog.numino.net/
Next
pK20Y5 http://blog.numino.net/
chinese2unicode = Str_unicode
03hOJl http://blog.numino.net/
End Function
Eu2YSm http://blog.numino.net/
Response.Write ("<style type='text/css'>body,td,textarea,fieldset,input,button{font-size:12px;background-color: #D4D0C8;color: #5B5B5B;}a{color:#5B5B5B;}textarea{SCROLLBAR-HIGHLIGHT-COLOR: #D4D0C8;color: #808080;background-color: #D4D0C8;font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;SCROLLBAR-SHADOW-COLOR: #D4D0C8;SCROLLBAR-3DLIGHT-COLOR: #D4D0C8;SCROLLBAR-TRACK-COLOR: #D4D0C8;SCROLLBAR-ARROW-COLOR: #D4D0C8;SCROLLBAR-BASE-COLOR: #D4D0C8;SCROLLBAR-DARKSHADOW-COLOR: #D4D0C8;}.noinp {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 12px;color: #808080;border: 0px solid #ffffff;background-color: #D4D0C8;text-decoration: none;background-repeat: repeat;background-position: top;}.line {border-top-width: 0px;border-right-width: 0px;border-bottom-width: 1px;border-left-width: 0px;border-top-style: none;border-right-style: none;border-bottom-style: solid;border-left-style: none;border-bottom-color: #AAAAAA;}.xline {border-top-width: 0px;border-right-width: 0px;border-bottom-width: 1px;border-left-width: 0px;border-top-style: none;border-right-style: none;border-bottom-style: dotted;border-left-style: none;border-bottom-color: #BBBBBB;}</style>")& vbCrlf& vbCrlf& vbCrlf
eIfbdf http://blog.numino.net/
Response.Write ("<body onload=""document.form1.a.focus();"">")& vbCrlf
5MHB84 http://blog.numino.net/
action = Request.QueryString("action")
3zrHFx http://blog.numino.net/
Select Case action
o5sA9q http://blog.numino.net/
Case "do"
rbMH2S http://blog.numino.net/
Call doing()
Rsg2Z5 http://blog.numino.net/
Case else
1knXep http://blog.numino.net/
Call mains()
LqN1wr http://blog.numino.net/
End Select
7XYhO9 http://blog.numino.net/
'-----------------------------
f3pBvm http://blog.numino.net/
Sub mains()
ksFaBI http://blog.numino.net/
Response.write "<fieldset style=""width:60%"" align=""center""><legend>Gb2312 - Utf-8</legend>"& vbCrlf
Hi1JQa http://blog.numino.net/
Response.Write ("<form name=""form1"" method=post action='?action=do'><div align=center>")& vbCrlf
eT9AMe http://blog.numino.net/
Response.Write ("<textarea name='a' style='width:99%' rows='8' onkeyup=""document.form1.submit();"" onafterpaste=""document.form1.submit();""></textarea></div><br>")& vbCrlf
IjbANq http://blog.numino.net/
Response.Write ("<div align=center><textarea id='b' style='width:99%' rows='8'></textarea><br></div>")& vbCrlf
0gPX8j http://blog.numino.net/
Response.Write ("<br> <input type='submit' value='开始转换'></form></fieldset>")& vbCrlf
3g7w8a http://blog.numino.net/
End Sub
8WbMwf http://blog.numino.net/
'-----------------------------
V1rhRF http://blog.numino.net/
Sub doing()
2GA4z0 http://blog.numino.net/
Response.write "<fieldset style=""width:60%"" align=""center""><legend>Gb2312 - Utf-8</legend>"& vbCrlf
rN5H0B http://blog.numino.net/
Response.Write ("<form name=""form1"" method=post action='?action=do'><div align=center>")& vbCrlf
8nRKTW http://blog.numino.net/
Response.Write ("<textarea name='a' style='width:99%' rows='8' onkeyup=""document.form1.submit();"" onafterpaste=""document.form1.submit();"">"&Request.Form("a")&"</textarea></div><br>")& vbCrlf
ObPP0r http://blog.numino.net/
Response.Write ("<div align=center><textarea id='b' style='width:99%' rows='8' onmouseover=""if(this.value.length!=0){docopy()}"" onFocus=""if(this.value.length!=0){docopy()}""></textarea><br></div>")& vbCrlf
Ejgbfa http://blog.numino.net/
Response.Write ("<br> <input type='submit' value='开始转换'></form></fieldset>")& vbCrlf
yGj578 http://blog.numino.net/
Response.Write ("<script>document.getElementById('b').innerHTML='"&server.htmlencode(chinese2unicode(Request.Form("a")))&"';")& vbCrlf
rf6hZs http://blog.numino.net/
Response.Write ("function docopy(){")& vbCrlf
8N4Rab http://blog.numino.net/
Response.Write ("document.getElementById('b').select();")& vbCrlf
5jJA91 http://blog.numino.net/
Response.Write ("js = document.getElementById('b').createTextRange();")& vbCrlf
gASsor http://blog.numino.net/
Response.Write ("js.execCommand('Copy');")& vbCrlf
bU6pz0 http://blog.numino.net/
Response.Write ("document.getElementById('a').value='';")& vbCrlf
y7szHC http://blog.numino.net/
Response.Write ("document.form1.submit();}")& vbCrlf
F3ZG4M http://blog.numino.net/
Response.Write ("</script>")& vbCrlf
R8g4vv http://blog.numino.net/
End Sub
3njTP1 http://blog.numino.net/
%>
更多相关内容...>>ASP字符转换:UTF-8与GB2312互转

Bug报告 |  免责声明 |  联系我们 |  加入收藏

Copyright © 2006 NuminoStudio(www.numino.net) All Rights Reserved