更多相关内容...>>ASP字符转换:UTF-8与GB2312互转
ASP字符转换:UTF-8与GB2312互转
UTF-8转GB2312函数
bvc8lB http://blog.numino.net/
<%
E1tN6K http://blog.numino.net/
'用途:將UTF-8編碼漢字轉換為GB2312碼,兼容英文和數字
3hLvjr http://blog.numino.net/
'版權:雖說是原創,其實也參考了別人的部分算法
id3XcW 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")
rx326D http://blog.numino.net/
function UTF2GB(UTFStr)
ABXMb8 http://blog.numino.net/
for Dig=1 to len(UTFStr)
l76CQN http://blog.numino.net/
if mid(UTFStr,Dig,1)="%" then
tT42Kk http://blog.numino.net/
if len(UTFStr) >= Dig+8 then
sDOb65 http://blog.numino.net/
GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
JjUO72 http://blog.numino.net/
Dig=Dig+8
LqJ4YI http://blog.numino.net/
else
VmOskK http://blog.numino.net/
GBStr=GBStr & mid(UTFStr,Dig,1)
0a1Mjp http://blog.numino.net/
end if
k6PZ7t http://blog.numino.net/
else
WmSMgq http://blog.numino.net/
GBStr=GBStr & mid(UTFStr,Dig,1)
30YZqC http://blog.numino.net/
end if
tbnRaW http://blog.numino.net/
next
hbV5h3 http://blog.numino.net/
UTF2GB=GBStr
YW14nN http://blog.numino.net/
end function
uBUjtB http://blog.numino.net/
function ConvChinese(x)
426KHt http://blog.numino.net/
A=split(mid(x,2),"%")
48vvIv http://blog.numino.net/
i=0
8LKOPp http://blog.numino.net/
j=0
ZhTcTz http://blog.numino.net/
for i=0 to ubound(A)
Eq0eDP http://blog.numino.net/
A(i)=c16to2(A(i))
pFJhlL http://blog.numino.net/
next
XjuR4p http://blog.numino.net/
for i=0 to ubound(A)-1
BrwN4I http://blog.numino.net/
DigS=instr(A(i),"0")
S8ESGo http://blog.numino.net/
Unicode=""
XM9SOY http://blog.numino.net/
for j=1 to DigS-1
G767k4 http://blog.numino.net/
if j=1 then
zJ57gJ http://blog.numino.net/
A(i)=right(A(i),len(A(i))-DigS)
7ggMyQ http://blog.numino.net/
Unicode=Unicode & A(i)
YvX83e http://blog.numino.net/
else
O3w9Ss http://blog.numino.net/
i=i+1
aOlWZm http://blog.numino.net/
A(i)=right(A(i),len(A(i))-2)
iT1mP3 http://blog.numino.net/
Unicode=Unicode & A(i)
FC1417 http://blog.numino.net/
end if
1LF3dP http://blog.numino.net/
next
Id3fa8 http://blog.numino.net/
if len(c2to16(Unicode))=4 then
Nbpk9I http://blog.numino.net/
ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode)))
5ylRVm http://blog.numino.net/
else
8fP613 http://blog.numino.net/
ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode)))
8KHn6G http://blog.numino.net/
end if
X192p3 http://blog.numino.net/
next
FeJ79D http://blog.numino.net/
end function
3s91Et http://blog.numino.net/
function c2to16(x)
HOOte9 http://blog.numino.net/
i=1
0Ztixf http://blog.numino.net/
for i=1 to len(x) step 4
G7TX3B http://blog.numino.net/
c2to16=c2to16 & hex(c2to10(mid(x,i,4)))
cIA3AU http://blog.numino.net/
next
953yAJ http://blog.numino.net/
end function
G6OXDy http://blog.numino.net/
function c2to10(x)
Ep4Djt http://blog.numino.net/
c2to10=0
JVCZ2w http://blog.numino.net/
if x="0" then exit function
D3JdEg http://blog.numino.net/
i=0
224ek0 http://blog.numino.net/
for i= 0 to len(x) -1
r2F17B http://blog.numino.net/
if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
H30V8L http://blog.numino.net/
next
W6btiA http://blog.numino.net/
end function
AdpGCv http://blog.numino.net/
function c16to2(x)
T8bu9Z http://blog.numino.net/
i=0
Pv2H6V http://blog.numino.net/
for i=1 to len(trim(x))
zVDHZD http://blog.numino.net/
tempstr= c10to2(cint(int("&h" & mid(x,i,1))))
152vS0 http://blog.numino.net/
do while len(tempstr)<4
nzg6GR http://blog.numino.net/
tempstr="0" & tempstr
hRII8W http://blog.numino.net/
loop
0AjX27 http://blog.numino.net/
c16to2=c16to2 & tempstr
ZeT3RB http://blog.numino.net/
next
c097qt http://blog.numino.net/
end function
0XN0GT http://blog.numino.net/
function c10to2(x)
txA82B http://blog.numino.net/
mysign=sgn(x)
Kfp1zD http://blog.numino.net/
x=abs(x)
0gJH1a http://blog.numino.net/
DigS=1
vI1h3j http://blog.numino.net/
do
50C6cO http://blog.numino.net/
if x<2^DigS then
wQ89VS http://blog.numino.net/
exit do
K7M7PR http://blog.numino.net/
else
B9j42E http://blog.numino.net/
DigS=DigS+1
szIJ8r http://blog.numino.net/
end if
r0uErk http://blog.numino.net/
loop
c9szJ4 http://blog.numino.net/
tempnum=x
98Bxpb http://blog.numino.net/
i=0
Jvy5q8 http://blog.numino.net/
for i=DigS to 1 step-1
1KYh0q http://blog.numino.net/
if tempnum>=2^(i-1) then
Zsx6rH http://blog.numino.net/
tempnum=tempnum-2^(i-1)
ytFhKZ http://blog.numino.net/
c10to2=c10to2 & "1"
YbsIj7 http://blog.numino.net/
else
u71ZYf http://blog.numino.net/
c10to2=c10to2 & "0"
4JiN80 http://blog.numino.net/
end if
AIKb20 http://blog.numino.net/
next
IFqai9 http://blog.numino.net/
if mysign=-1 then c10to2="-" & c10to2
0lp4TA http://blog.numino.net/
end function
1hWoDQ http://blog.numino.net/
%>
I7xOUF http://blog.numino.net/
-----------------------------------------------------------------------------------------------------------------------------
P8ur5V http://blog.numino.net/
ASP编码转换函数GB2312转换UTF-8
IQlve5 http://blog.numino.net/
<%
4yNBSk http://blog.numino.net/
Function chinese2unicode(Str)
IW78aa http://blog.numino.net/
dim i
PffgTk http://blog.numino.net/
dim Str_one
N3mSYw http://blog.numino.net/
dim Str_unicode
Mp2L8Y http://blog.numino.net/
For i=1 to len(Str)
ILn02K http://blog.numino.net/
Str_one=Mid(Str,i,1)
629G5U http://blog.numino.net/
Str_unicode=Str_unicode&chr(38)
eJysId http://blog.numino.net/
Str_unicode=Str_unicode&chr(35)
bkfTrP http://blog.numino.net/
Str_unicode=Str_unicode&chr(120)
9V5tQP http://blog.numino.net/
Str_unicode=Str_unicode& Hex(ascw(Str_one))
h3Q1Yy http://blog.numino.net/
Str_unicode=Str_unicode&chr(59)
j2Idt6 http://blog.numino.net/
Next
NMqV2d http://blog.numino.net/
chinese2unicode = Str_unicode
Oqkg62 http://blog.numino.net/
End Function
WZrwtt 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
IIO0e9 http://blog.numino.net/
Response.Write ("<body onload=""document.form1.a.focus();"">")& vbCrlf
1g9T1d http://blog.numino.net/
action = Request.QueryString("action")
P70mzD http://blog.numino.net/
Select Case action
TrNY2w http://blog.numino.net/
Case "do"
e7qZje http://blog.numino.net/
Call doing()
6O6Tzq http://blog.numino.net/
Case else
x7tpTY http://blog.numino.net/
Call mains()
xA75p7 http://blog.numino.net/
End Select
s9YXZr http://blog.numino.net/
'-----------------------------
ct7drq http://blog.numino.net/
Sub mains()
0GpfsD http://blog.numino.net/
Response.write "<fieldset style=""width:60%"" align=""center""><legend>Gb2312 - Utf-8</legend>"& vbCrlf
VmkEbl http://blog.numino.net/
Response.Write ("<form name=""form1"" method=post action='?action=do'><div align=center>")& vbCrlf
H15WO4 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
87Br04 http://blog.numino.net/
Response.Write ("<div align=center><textarea id='b' style='width:99%' rows='8'></textarea><br></div>")& vbCrlf
wB6ZSd http://blog.numino.net/
Response.Write ("<br> <input type='submit' value='开始转换'></form></fieldset>")& vbCrlf
iryz6G http://blog.numino.net/
End Sub
i6qGrF http://blog.numino.net/
'-----------------------------
Jg38Fz http://blog.numino.net/
Sub doing()
7hxSc4 http://blog.numino.net/
Response.write "<fieldset style=""width:60%"" align=""center""><legend>Gb2312 - Utf-8</legend>"& vbCrlf
NaRIMb http://blog.numino.net/
Response.Write ("<form name=""form1"" method=post action='?action=do'><div align=center>")& vbCrlf
4rYI5u 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
tzeuj8 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
lMb6FN http://blog.numino.net/
Response.Write ("<br> <input type='submit' value='开始转换'></form></fieldset>")& vbCrlf
rc7Q94 http://blog.numino.net/
Response.Write ("<script>document.getElementById('b').innerHTML='"&server.htmlencode(chinese2unicode(Request.Form("a")))&"';")& vbCrlf
LX9fjS http://blog.numino.net/
Response.Write ("function docopy(){")& vbCrlf
Dr57wH http://blog.numino.net/
Response.Write ("document.getElementById('b').select();")& vbCrlf
GXoTYK http://blog.numino.net/
Response.Write ("js = document.getElementById('b').createTextRange();")& vbCrlf
X3k41B http://blog.numino.net/
Response.Write ("js.execCommand('Copy');")& vbCrlf
izAdlq http://blog.numino.net/
Response.Write ("document.getElementById('a').value='';")& vbCrlf
dbvl66 http://blog.numino.net/
Response.Write ("document.form1.submit();}")& vbCrlf
KwRLWY http://blog.numino.net/
Response.Write ("</script>")& vbCrlf
BDu6TC http://blog.numino.net/
End Sub
NH8yEw http://blog.numino.net/
%>
更多相关内容...>>ASP字符转换:UTF-8与GB2312互转

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

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