更多相关内容...>>ASP字符转换:UTF-8与GB2312互转
ASP字符转换:UTF-8与GB2312互转
UTF-8转GB2312函数
lLmNp0 http://www.numino.net
<%
SxgFbP http://www.numino.net
'用途:將UTF-8編碼漢字轉換為GB2312碼,兼容英文和數字
d3V96k http://www.numino.net
'版權:雖說是原創,其實也參考了別人的部分算法
nXIj7d http://www.numino.net
'用法:Response.write UTF2GB("%E9%83%BD%E5%B8%82%E6%83%85%E7%B7%A3 %E6%98%9F%E5%BA%A7")
e2ME67 http://www.numino.net
function UTF2GB(UTFStr)
kpBb15 http://www.numino.net
for Dig=1 to len(UTFStr)
35ch6q http://www.numino.net
if mid(UTFStr,Dig,1)="%" then
Q4TEs5 http://www.numino.net
if len(UTFStr) >= Dig+8 then
ka9g11 http://www.numino.net
GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
8g99UV http://www.numino.net
Dig=Dig+8
t0F80b http://www.numino.net
else
L797No http://www.numino.net
GBStr=GBStr & mid(UTFStr,Dig,1)
g55w9a http://www.numino.net
end if
KtsjZm http://www.numino.net
else
383750 http://www.numino.net
GBStr=GBStr & mid(UTFStr,Dig,1)
79Ovu5 http://www.numino.net
end if
sN23i5 http://www.numino.net
next
x1aQtv http://www.numino.net
UTF2GB=GBStr
GW3qIG http://www.numino.net
end function
W3noNH http://www.numino.net
function ConvChinese(x)
7mh7dk http://www.numino.net
A=split(mid(x,2),"%")
eVn7UO http://www.numino.net
i=0
10Sq1K http://www.numino.net
j=0
zo7xs7 http://www.numino.net
for i=0 to ubound(A)
d14CBm http://www.numino.net
A(i)=c16to2(A(i))
B5oonL http://www.numino.net
next
T4vG0G http://www.numino.net
for i=0 to ubound(A)-1
gp49iX http://www.numino.net
DigS=instr(A(i),"0")
wJ25Q1 http://www.numino.net
Unicode=""
20On71 http://www.numino.net
for j=1 to DigS-1
4e940F http://www.numino.net
if j=1 then
6YZJS1 http://www.numino.net
A(i)=right(A(i),len(A(i))-DigS)
ktibV2 http://www.numino.net
Unicode=Unicode & A(i)
Aqr6XE http://www.numino.net
else
GzUQ7q http://www.numino.net
i=i+1
0hT1SH http://www.numino.net
A(i)=right(A(i),len(A(i))-2)
x0D5uR http://www.numino.net
Unicode=Unicode & A(i)
62qQ4v http://www.numino.net
end if
77RX2X http://www.numino.net
next
Y4xijU http://www.numino.net
if len(c2to16(Unicode))=4 then
j6Bivy http://www.numino.net
ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode)))
t3tVlc http://www.numino.net
else
d74cG8 http://www.numino.net
ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode)))
G2SJj5 http://www.numino.net
end if
8RtEaD http://www.numino.net
next
T8UTIg http://www.numino.net
end function
GPY7a7 http://www.numino.net
function c2to16(x)
6S9RdS http://www.numino.net
i=1
GSbd7a http://www.numino.net
for i=1 to len(x) step 4
0nebp8 http://www.numino.net
c2to16=c2to16 & hex(c2to10(mid(x,i,4)))
09pnN0 http://www.numino.net
next
kWk82E http://www.numino.net
end function
dbhlvx http://www.numino.net
function c2to10(x)
r2EFx8 http://www.numino.net
c2to10=0
e8S90t http://www.numino.net
if x="0" then exit function
G4mPgL http://www.numino.net
i=0
ucLxWL http://www.numino.net
for i= 0 to len(x) -1
6J4ITN http://www.numino.net
if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
JdFkbq http://www.numino.net
next
YoSdRq http://www.numino.net
end function
L99Ap3 http://www.numino.net
function c16to2(x)
8p3Lpn http://www.numino.net
i=0
iEzRBa http://www.numino.net
for i=1 to len(trim(x))
0r5qgJ http://www.numino.net
tempstr= c10to2(cint(int("&h" & mid(x,i,1))))
mslF18 http://www.numino.net
do while len(tempstr)<4
it97F7 http://www.numino.net
tempstr="0" & tempstr
rD1gf8 http://www.numino.net
loop
EJLtuA http://www.numino.net
c16to2=c16to2 & tempstr
rBGd9c http://www.numino.net
next
Ip3zNx http://www.numino.net
end function
LOuSDg http://www.numino.net
function c10to2(x)
DGOY6f http://www.numino.net
mysign=sgn(x)
zCXKx8 http://www.numino.net
x=abs(x)
235i64 http://www.numino.net
DigS=1
SfIS6v http://www.numino.net
do
s6g6KA http://www.numino.net
if x<2^DigS then
t41X2q http://www.numino.net
exit do
FLdfJB http://www.numino.net
else
1fdnOu http://www.numino.net
DigS=DigS+1
PKK50A http://www.numino.net
end if
D7CGh3 http://www.numino.net
loop
neN3zN http://www.numino.net
tempnum=x
57fs1l http://www.numino.net
i=0
7Pjo3s http://www.numino.net
for i=DigS to 1 step-1
B9WNvC http://www.numino.net
if tempnum>=2^(i-1) then
L6jM6C http://www.numino.net
tempnum=tempnum-2^(i-1)
Z3GBNN http://www.numino.net
c10to2=c10to2 & "1"
3Dpbt7 http://www.numino.net
else
ZC41W1 http://www.numino.net
c10to2=c10to2 & "0"
QYEEE7 http://www.numino.net
end if
FBJqhU http://www.numino.net
next
pDg29H http://www.numino.net
if mysign=-1 then c10to2="-" & c10to2
07VS69 http://www.numino.net
end function
xaflzz http://www.numino.net
%>
5JdiT1 http://www.numino.net
-----------------------------------------------------------------------------------------------------------------------------
DvtTcr http://www.numino.net
ASP编码转换函数GB2312转换UTF-8
Y1a07L http://www.numino.net
<%
CGV3Gl http://www.numino.net
Function chinese2unicode(Str)
Ng7WUj http://www.numino.net
dim i
9VszvK http://www.numino.net
dim Str_one
l4JFLx http://www.numino.net
dim Str_unicode
DiaxKp http://www.numino.net
For i=1 to len(Str)
C20SHe http://www.numino.net
Str_one=Mid(Str,i,1)
p3yrs8 http://www.numino.net
Str_unicode=Str_unicode&chr(38)
3pgi7j http://www.numino.net
Str_unicode=Str_unicode&chr(35)
BTREN3 http://www.numino.net
Str_unicode=Str_unicode&chr(120)
in3rHB http://www.numino.net
Str_unicode=Str_unicode& Hex(ascw(Str_one))
oIn1Xp http://www.numino.net
Str_unicode=Str_unicode&chr(59)
6g5Dl2 http://www.numino.net
Next
9PvG1y http://www.numino.net
chinese2unicode = Str_unicode
lf8ZqY http://www.numino.net
End Function
5WJT2k http://www.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
2z2PL9 http://www.numino.net
Response.Write ("<body onload=""document.form1.a.focus();"">")& vbCrlf
B4ASdm http://www.numino.net
action = Request.QueryString("action")
cD3eCc http://www.numino.net
Select Case action
NIC7mh http://www.numino.net
Case "do"
B67NVW http://www.numino.net
Call doing()
dR5Md8 http://www.numino.net
Case else
aPAzU6 http://www.numino.net
Call mains()
pPaDr1 http://www.numino.net
End Select
XIMCWP http://www.numino.net
'-----------------------------
ywaIz1 http://www.numino.net
Sub mains()
5GzIKO http://www.numino.net
Response.write "<fieldset style=""width:60%"" align=""center""><legend>Gb2312 - Utf-8</legend>"& vbCrlf
mU5bE3 http://www.numino.net
Response.Write ("<form name=""form1"" method=post action='?action=do'><div align=center>")& vbCrlf
PYAWrh http://www.numino.net
Response.Write ("<textarea name='a' style='width:99%' rows='8' onkeyup=""document.form1.submit();"" onafterpaste=""document.form1.submit();""></textarea></div><br>")& vbCrlf
mF54JN http://www.numino.net
Response.Write ("<div align=center><textarea id='b' style='width:99%' rows='8'></textarea><br></div>")& vbCrlf
pbEpvG http://www.numino.net
Response.Write ("<br> <input type='submit' value='开始转换'></form></fieldset>")& vbCrlf
Z25lpF http://www.numino.net
End Sub
eAd5L3 http://www.numino.net
'-----------------------------
dnk2u3 http://www.numino.net
Sub doing()
zPCxF5 http://www.numino.net
Response.write "<fieldset style=""width:60%"" align=""center""><legend>Gb2312 - Utf-8</legend>"& vbCrlf
6fw8zH http://www.numino.net
Response.Write ("<form name=""form1"" method=post action='?action=do'><div align=center>")& vbCrlf
Z3Rhqo http://www.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
DGttnH http://www.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
s60CDl http://www.numino.net
Response.Write ("<br> <input type='submit' value='开始转换'></form></fieldset>")& vbCrlf
NyJRix http://www.numino.net
Response.Write ("<script>document.getElementById('b').innerHTML='"&server.htmlencode(chinese2unicode(Request.Form("a")))&"';")& vbCrlf
dOVlVB http://www.numino.net
Response.Write ("function docopy(){")& vbCrlf
2zpz1t http://www.numino.net
Response.Write ("document.getElementById('b').select();")& vbCrlf
dFZaQe http://www.numino.net
Response.Write ("js = document.getElementById('b').createTextRange();")& vbCrlf
c5QVED http://www.numino.net
Response.Write ("js.execCommand('Copy');")& vbCrlf
J2NTWD http://www.numino.net
Response.Write ("document.getElementById('a').value='';")& vbCrlf
BjVYwy http://www.numino.net
Response.Write ("document.form1.submit();}")& vbCrlf
s6823k http://www.numino.net
Response.Write ("</script>")& vbCrlf
fR638v http://www.numino.net
End Sub
y4770Q http://www.numino.net
%>
更多相关内容...>>ASP字符转换:UTF-8与GB2312互转

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

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