更多相关内容...>>ASP字符转换:UTF-8与GB2312互转
ASP字符转换:UTF-8与GB2312互转
UTF-8转GB2312函数
rtK4i5 http://blog.numino.net/
<%
w6KP4C http://blog.numino.net/
'用途:將UTF-8編碼漢字轉換為GB2312碼,兼容英文和數字
1de5mS http://blog.numino.net/
'版權:雖說是原創,其實也參考了別人的部分算法
2vEsmu 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")
PWOinn http://blog.numino.net/
function UTF2GB(UTFStr)
PQ142V http://blog.numino.net/
for Dig=1 to len(UTFStr)
RjTyw0 http://blog.numino.net/
if mid(UTFStr,Dig,1)="%" then
7F8kZ7 http://blog.numino.net/
if len(UTFStr) >= Dig+8 then
UesjSF http://blog.numino.net/
GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
t27CE8 http://blog.numino.net/
Dig=Dig+8
WCjbk9 http://blog.numino.net/
else
m7a8RD http://blog.numino.net/
GBStr=GBStr & mid(UTFStr,Dig,1)
KxQWm5 http://blog.numino.net/
end if
Q66Cw1 http://blog.numino.net/
else
38zup2 http://blog.numino.net/
GBStr=GBStr & mid(UTFStr,Dig,1)
eVmAZO http://blog.numino.net/
end if
n667vP http://blog.numino.net/
next
xUShC4 http://blog.numino.net/
UTF2GB=GBStr
80u134 http://blog.numino.net/
end function
2CaUB7 http://blog.numino.net/
function ConvChinese(x)
F9mPg9 http://blog.numino.net/
A=split(mid(x,2),"%")
rp14pV http://blog.numino.net/
i=0
sZjXaW http://blog.numino.net/
j=0
1gx149 http://blog.numino.net/
for i=0 to ubound(A)
b22US1 http://blog.numino.net/
A(i)=c16to2(A(i))
d6m1u6 http://blog.numino.net/
next
k4MUws http://blog.numino.net/
for i=0 to ubound(A)-1
l08dqQ http://blog.numino.net/
DigS=instr(A(i),"0")
9MP5hi http://blog.numino.net/
Unicode=""
M51oFc http://blog.numino.net/
for j=1 to DigS-1
6G8TNf http://blog.numino.net/
if j=1 then
EBLp6W http://blog.numino.net/
A(i)=right(A(i),len(A(i))-DigS)
xOQIDY http://blog.numino.net/
Unicode=Unicode & A(i)
6wh7ko http://blog.numino.net/
else
RS9T5y http://blog.numino.net/
i=i+1
6hJGzI http://blog.numino.net/
A(i)=right(A(i),len(A(i))-2)
uVRjq6 http://blog.numino.net/
Unicode=Unicode & A(i)
RatKwW http://blog.numino.net/
end if
BFPbNo http://blog.numino.net/
next
tyZUxd http://blog.numino.net/
if len(c2to16(Unicode))=4 then
my7EY6 http://blog.numino.net/
ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode)))
cL3zfU http://blog.numino.net/
else
O002Wn http://blog.numino.net/
ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode)))
VnBsqa http://blog.numino.net/
end if
W6x1Lm http://blog.numino.net/
next
fT0906 http://blog.numino.net/
end function
kUy5P7 http://blog.numino.net/
function c2to16(x)
38y77E http://blog.numino.net/
i=1
HiGXFn http://blog.numino.net/
for i=1 to len(x) step 4
M22Fcf http://blog.numino.net/
c2to16=c2to16 & hex(c2to10(mid(x,i,4)))
93Ehgf http://blog.numino.net/
next
vn6rEp http://blog.numino.net/
end function
CwNnl8 http://blog.numino.net/
function c2to10(x)
22nza0 http://blog.numino.net/
c2to10=0
cLA0tG http://blog.numino.net/
if x="0" then exit function
5Ki7IQ http://blog.numino.net/
i=0
oha1Ob http://blog.numino.net/
for i= 0 to len(x) -1
Yx7nb2 http://blog.numino.net/
if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
8wmwuf http://blog.numino.net/
next
uGV602 http://blog.numino.net/
end function
T5H93W http://blog.numino.net/
function c16to2(x)
01hbs6 http://blog.numino.net/
i=0
QjWfiY http://blog.numino.net/
for i=1 to len(trim(x))
E3AZCi http://blog.numino.net/
tempstr= c10to2(cint(int("&h" & mid(x,i,1))))
drGn08 http://blog.numino.net/
do while len(tempstr)<4
mVLAs2 http://blog.numino.net/
tempstr="0" & tempstr
la1I1W http://blog.numino.net/
loop
F0JInE http://blog.numino.net/
c16to2=c16to2 & tempstr
04dDni http://blog.numino.net/
next
x902Pi http://blog.numino.net/
end function
nQP8Zu http://blog.numino.net/
function c10to2(x)
nsvrUx http://blog.numino.net/
mysign=sgn(x)
Div7n7 http://blog.numino.net/
x=abs(x)
VU1QGJ http://blog.numino.net/
DigS=1
buZe5K http://blog.numino.net/
do
o01cF5 http://blog.numino.net/
if x<2^DigS then
pYrv19 http://blog.numino.net/
exit do
9UNrLE http://blog.numino.net/
else
vdn02o http://blog.numino.net/
DigS=DigS+1
8J8LSb http://blog.numino.net/
end if
cwxoqZ http://blog.numino.net/
loop
XvQsty http://blog.numino.net/
tempnum=x
9idP24 http://blog.numino.net/
i=0
2NjzMm http://blog.numino.net/
for i=DigS to 1 step-1
eOd2Hw http://blog.numino.net/
if tempnum>=2^(i-1) then
Z51buk http://blog.numino.net/
tempnum=tempnum-2^(i-1)
ceTWA3 http://blog.numino.net/
c10to2=c10to2 & "1"
b37ksU http://blog.numino.net/
else
tz38aK http://blog.numino.net/
c10to2=c10to2 & "0"
Azw7gd http://blog.numino.net/
end if
MxPzW0 http://blog.numino.net/
next
EVY9gj http://blog.numino.net/
if mysign=-1 then c10to2="-" & c10to2
3PZ2t6 http://blog.numino.net/
end function
tbBX5g http://blog.numino.net/
%>
875lVx http://blog.numino.net/
-----------------------------------------------------------------------------------------------------------------------------
cemyUJ http://blog.numino.net/
ASP编码转换函数GB2312转换UTF-8
V5unoz http://blog.numino.net/
<%
Jjlld3 http://blog.numino.net/
Function chinese2unicode(Str)
9oxbM6 http://blog.numino.net/
dim i
Fz2e6n http://blog.numino.net/
dim Str_one
vRBcU2 http://blog.numino.net/
dim Str_unicode
iESFq4 http://blog.numino.net/
For i=1 to len(Str)
1WLIqB http://blog.numino.net/
Str_one=Mid(Str,i,1)
D573W9 http://blog.numino.net/
Str_unicode=Str_unicode&chr(38)
36t539 http://blog.numino.net/
Str_unicode=Str_unicode&chr(35)
Zysopm http://blog.numino.net/
Str_unicode=Str_unicode&chr(120)
OQ6ppA http://blog.numino.net/
Str_unicode=Str_unicode& Hex(ascw(Str_one))
O223Fr http://blog.numino.net/
Str_unicode=Str_unicode&chr(59)
9q4Odf http://blog.numino.net/
Next
RSJ54z http://blog.numino.net/
chinese2unicode = Str_unicode
tEwX43 http://blog.numino.net/
End Function
fpTZ7l 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
dPCD22 http://blog.numino.net/
Response.Write ("<body onload=""document.form1.a.focus();"">")& vbCrlf
oPR2Xs http://blog.numino.net/
action = Request.QueryString("action")
Pr7Ws8 http://blog.numino.net/
Select Case action
SXCD8R http://blog.numino.net/
Case "do"
hT3u75 http://blog.numino.net/
Call doing()
PUJH4G http://blog.numino.net/
Case else
t4N31t http://blog.numino.net/
Call mains()
Bh5pOg http://blog.numino.net/
End Select
P23xfD http://blog.numino.net/
'-----------------------------
R32JOR http://blog.numino.net/
Sub mains()
g9kk8b http://blog.numino.net/
Response.write "<fieldset style=""width:60%"" align=""center""><legend>Gb2312 - Utf-8</legend>"& vbCrlf
34S79k http://blog.numino.net/
Response.Write ("<form name=""form1"" method=post action='?action=do'><div align=center>")& vbCrlf
tRBWid 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
4brZ7P http://blog.numino.net/
Response.Write ("<div align=center><textarea id='b' style='width:99%' rows='8'></textarea><br></div>")& vbCrlf
7sPxnJ http://blog.numino.net/
Response.Write ("<br> <input type='submit' value='开始转换'></form></fieldset>")& vbCrlf
984Wr0 http://blog.numino.net/
End Sub
aNqEBK http://blog.numino.net/
'-----------------------------
qJz3jI http://blog.numino.net/
Sub doing()
dKCcxv http://blog.numino.net/
Response.write "<fieldset style=""width:60%"" align=""center""><legend>Gb2312 - Utf-8</legend>"& vbCrlf
1PYLPz http://blog.numino.net/
Response.Write ("<form name=""form1"" method=post action='?action=do'><div align=center>")& vbCrlf
GU4zH7 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
9fo5yb 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
4K1y2A http://blog.numino.net/
Response.Write ("<br> <input type='submit' value='开始转换'></form></fieldset>")& vbCrlf
d239l4 http://blog.numino.net/
Response.Write ("<script>document.getElementById('b').innerHTML='"&server.htmlencode(chinese2unicode(Request.Form("a")))&"';")& vbCrlf
Iu9Ik6 http://blog.numino.net/
Response.Write ("function docopy(){")& vbCrlf
z2b7iU http://blog.numino.net/
Response.Write ("document.getElementById('b').select();")& vbCrlf
M1Ku87 http://blog.numino.net/
Response.Write ("js = document.getElementById('b').createTextRange();")& vbCrlf
0NyuH1 http://blog.numino.net/
Response.Write ("js.execCommand('Copy');")& vbCrlf
Jtfesy http://blog.numino.net/
Response.Write ("document.getElementById('a').value='';")& vbCrlf
u7Q1p0 http://blog.numino.net/
Response.Write ("document.form1.submit();}")& vbCrlf
pQP7Np http://blog.numino.net/
Response.Write ("</script>")& vbCrlf
QBv1D4 http://blog.numino.net/
End Sub
mZ8QPg http://blog.numino.net/
%>
更多相关内容...>>ASP字符转换:UTF-8与GB2312互转

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

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