更多相关内容...>>ASP字符转换:UTF-8与GB2312互转
ASP字符转换:UTF-8与GB2312互转
UTF-8转GB2312函数
W1IZ4k http://www.numino.net
<%
caFU6M http://www.numino.net
'用途:將UTF-8編碼漢字轉換為GB2312碼,兼容英文和數字
Udu4g7 http://www.numino.net
'版權:雖說是原創,其實也參考了別人的部分算法
cxO0pt 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")
S4oofg http://www.numino.net
function UTF2GB(UTFStr)
23R32K http://www.numino.net
for Dig=1 to len(UTFStr)
x99kbN http://www.numino.net
if mid(UTFStr,Dig,1)="%" then
SAb2rr http://www.numino.net
if len(UTFStr) >= Dig+8 then
61C001 http://www.numino.net
GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
llIuVH http://www.numino.net
Dig=Dig+8
38TWWl http://www.numino.net
else
B5ht55 http://www.numino.net
GBStr=GBStr & mid(UTFStr,Dig,1)
4W4fKM http://www.numino.net
end if
9zZm1t http://www.numino.net
else
xrdD5T http://www.numino.net
GBStr=GBStr & mid(UTFStr,Dig,1)
w01w72 http://www.numino.net
end if
j675E2 http://www.numino.net
next
qVYAmH http://www.numino.net
UTF2GB=GBStr
puwA4p http://www.numino.net
end function
4D66Qm http://www.numino.net
function ConvChinese(x)
lP74lC http://www.numino.net
A=split(mid(x,2),"%")
h1YYrl http://www.numino.net
i=0
J0GJsk http://www.numino.net
j=0
zy1kxW http://www.numino.net
for i=0 to ubound(A)
G32IUN http://www.numino.net
A(i)=c16to2(A(i))
jdYAUN http://www.numino.net
next
fWzjvU http://www.numino.net
for i=0 to ubound(A)-1
SA3YcC http://www.numino.net
DigS=instr(A(i),"0")
347E4b http://www.numino.net
Unicode=""
i7FFPw http://www.numino.net
for j=1 to DigS-1
Od0Q98 http://www.numino.net
if j=1 then
HBwq8F http://www.numino.net
A(i)=right(A(i),len(A(i))-DigS)
28r82w http://www.numino.net
Unicode=Unicode & A(i)
DJJg0V http://www.numino.net
else
kMEF4A http://www.numino.net
i=i+1
IaE3z7 http://www.numino.net
A(i)=right(A(i),len(A(i))-2)
ypiSWZ http://www.numino.net
Unicode=Unicode & A(i)
d4I5OI http://www.numino.net
end if
BzoxdJ http://www.numino.net
next
dtwoIB http://www.numino.net
if len(c2to16(Unicode))=4 then
OsUu4Y http://www.numino.net
ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode)))
01vX37 http://www.numino.net
else
s23Yyz http://www.numino.net
ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode)))
ICB6IG http://www.numino.net
end if
8ZCLn2 http://www.numino.net
next
IXFDIg http://www.numino.net
end function
SFo636 http://www.numino.net
function c2to16(x)
6nzaVV http://www.numino.net
i=1
HI21l8 http://www.numino.net
for i=1 to len(x) step 4
FipUHA http://www.numino.net
c2to16=c2to16 & hex(c2to10(mid(x,i,4)))
h9LS3Q http://www.numino.net
next
1QGLv1 http://www.numino.net
end function
85L03K http://www.numino.net
function c2to10(x)
Eywerq http://www.numino.net
c2to10=0
sNT5bH http://www.numino.net
if x="0" then exit function
2vi2fw http://www.numino.net
i=0
JSGsy3 http://www.numino.net
for i= 0 to len(x) -1
L7Yx8t http://www.numino.net
if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
C1zmqJ http://www.numino.net
next
qXAdso http://www.numino.net
end function
tyMnVP http://www.numino.net
function c16to2(x)
Ox46Ke http://www.numino.net
i=0
g0kXL3 http://www.numino.net
for i=1 to len(trim(x))
9td7Yq http://www.numino.net
tempstr= c10to2(cint(int("&h" & mid(x,i,1))))
gv4S79 http://www.numino.net
do while len(tempstr)<4
t4wRmE http://www.numino.net
tempstr="0" & tempstr
pOaYkm http://www.numino.net
loop
0YGCe8 http://www.numino.net
c16to2=c16to2 & tempstr
X6r2nN http://www.numino.net
next
IVLuVf http://www.numino.net
end function
c3iaP2 http://www.numino.net
function c10to2(x)
zbxNMa http://www.numino.net
mysign=sgn(x)
IE1pzY http://www.numino.net
x=abs(x)
9qMZfG http://www.numino.net
DigS=1
z0jmy7 http://www.numino.net
do
0m6wLD http://www.numino.net
if x<2^DigS then
v39bDH http://www.numino.net
exit do
N9dV8t http://www.numino.net
else
XV42p2 http://www.numino.net
DigS=DigS+1
MpE5pA http://www.numino.net
end if
M5EQ4y http://www.numino.net
loop
rKfaox http://www.numino.net
tempnum=x
eXr8AH http://www.numino.net
i=0
ocBd5G http://www.numino.net
for i=DigS to 1 step-1
A76TVs http://www.numino.net
if tempnum>=2^(i-1) then
4grIz3 http://www.numino.net
tempnum=tempnum-2^(i-1)
pnQYJM http://www.numino.net
c10to2=c10to2 & "1"
7AzFX1 http://www.numino.net
else
qR43VV http://www.numino.net
c10to2=c10to2 & "0"
DfOn5a http://www.numino.net
end if
GE9YYJ http://www.numino.net
next
0xGc9D http://www.numino.net
if mysign=-1 then c10to2="-" & c10to2
5KWbTh http://www.numino.net
end function
oF9bDD http://www.numino.net
%>
gUAo4C http://www.numino.net
-----------------------------------------------------------------------------------------------------------------------------
3Co6kl http://www.numino.net
ASP编码转换函数GB2312转换UTF-8
5h272D http://www.numino.net
<%
loFbjc http://www.numino.net
Function chinese2unicode(Str)
5MC1o3 http://www.numino.net
dim i
JyWJys http://www.numino.net
dim Str_one
hYpr0i http://www.numino.net
dim Str_unicode
GC9Cpj http://www.numino.net
For i=1 to len(Str)
LUPuh4 http://www.numino.net
Str_one=Mid(Str,i,1)
MItlN0 http://www.numino.net
Str_unicode=Str_unicode&chr(38)
R2PGs8 http://www.numino.net
Str_unicode=Str_unicode&chr(35)
6434om http://www.numino.net
Str_unicode=Str_unicode&chr(120)
l5d9YY http://www.numino.net
Str_unicode=Str_unicode& Hex(ascw(Str_one))
c5Tng6 http://www.numino.net
Str_unicode=Str_unicode&chr(59)
k2Esgn http://www.numino.net
Next
IP9EYP http://www.numino.net
chinese2unicode = Str_unicode
Xw086o http://www.numino.net
End Function
so28QR 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
rOAK5T http://www.numino.net
Response.Write ("<body onload=""document.form1.a.focus();"">")& vbCrlf
ZiT58u http://www.numino.net
action = Request.QueryString("action")
M4PCr4 http://www.numino.net
Select Case action
InA5E4 http://www.numino.net
Case "do"
JiVYFR http://www.numino.net
Call doing()
g6g9g7 http://www.numino.net
Case else
IxejrP http://www.numino.net
Call mains()
ySYmFb http://www.numino.net
End Select
u1DFyA http://www.numino.net
'-----------------------------
CVTm39 http://www.numino.net
Sub mains()
r5gSe6 http://www.numino.net
Response.write "<fieldset style=""width:60%"" align=""center""><legend>Gb2312 - Utf-8</legend>"& vbCrlf
4Bhici http://www.numino.net
Response.Write ("<form name=""form1"" method=post action='?action=do'><div align=center>")& vbCrlf
xvm6fg 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
5Pwgt4 http://www.numino.net
Response.Write ("<div align=center><textarea id='b' style='width:99%' rows='8'></textarea><br></div>")& vbCrlf
2aOP4w http://www.numino.net
Response.Write ("<br> <input type='submit' value='开始转换'></form></fieldset>")& vbCrlf
Ai04AU http://www.numino.net
End Sub
1Hr09J http://www.numino.net
'-----------------------------
xeS5A5 http://www.numino.net
Sub doing()
7VSF1Q http://www.numino.net
Response.write "<fieldset style=""width:60%"" align=""center""><legend>Gb2312 - Utf-8</legend>"& vbCrlf
jLJKDY http://www.numino.net
Response.Write ("<form name=""form1"" method=post action='?action=do'><div align=center>")& vbCrlf
iNIOOO 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
AQ5RrU 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
wSe6r8 http://www.numino.net
Response.Write ("<br> <input type='submit' value='开始转换'></form></fieldset>")& vbCrlf
hOzDiC http://www.numino.net
Response.Write ("<script>document.getElementById('b').innerHTML='"&server.htmlencode(chinese2unicode(Request.Form("a")))&"';")& vbCrlf
VMsW27 http://www.numino.net
Response.Write ("function docopy(){")& vbCrlf
wP0FXr http://www.numino.net
Response.Write ("document.getElementById('b').select();")& vbCrlf
bFGa3s http://www.numino.net
Response.Write ("js = document.getElementById('b').createTextRange();")& vbCrlf
2RV0CC http://www.numino.net
Response.Write ("js.execCommand('Copy');")& vbCrlf
36PrC8 http://www.numino.net
Response.Write ("document.getElementById('a').value='';")& vbCrlf
t69pgI http://www.numino.net
Response.Write ("document.form1.submit();}")& vbCrlf
uQcDJB http://www.numino.net
Response.Write ("</script>")& vbCrlf
t0B6Ro http://www.numino.net
End Sub
sg8bJ0 http://www.numino.net
%>
更多相关内容...>>ASP字符转换:UTF-8与GB2312互转

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

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