更多相关内容...>>ASP字符转换:UTF-8与GB2312互转
ASP字符转换:UTF-8与GB2312互转
UTF-8转GB2312函数
w5WFg1 http://blog.numino.net/
<%
Kmk2sM http://blog.numino.net/
'用途:將UTF-8編碼漢字轉換為GB2312碼,兼容英文和數字
h07TAb http://blog.numino.net/
'版權:雖說是原創,其實也參考了別人的部分算法
mL8OzI 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")
6hQq9l http://blog.numino.net/
function UTF2GB(UTFStr)
OcQE9y http://blog.numino.net/
for Dig=1 to len(UTFStr)
ASL6yV http://blog.numino.net/
if mid(UTFStr,Dig,1)="%" then
XduMtG http://blog.numino.net/
if len(UTFStr) >= Dig+8 then
SQawyv http://blog.numino.net/
GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
77Tqft http://blog.numino.net/
Dig=Dig+8
97X40b http://blog.numino.net/
else
9a8zD2 http://blog.numino.net/
GBStr=GBStr & mid(UTFStr,Dig,1)
YZ8x84 http://blog.numino.net/
end if
v7G4Bo http://blog.numino.net/
else
5S3VpJ http://blog.numino.net/
GBStr=GBStr & mid(UTFStr,Dig,1)
476e4T http://blog.numino.net/
end if
urwKYs http://blog.numino.net/
next
99u2Yu http://blog.numino.net/
UTF2GB=GBStr
Z1vWJ8 http://blog.numino.net/
end function
lYnhc9 http://blog.numino.net/
function ConvChinese(x)
hBTe5E http://blog.numino.net/
A=split(mid(x,2),"%")
lOhwTe http://blog.numino.net/
i=0
6lChf4 http://blog.numino.net/
j=0
6Z1GiO http://blog.numino.net/
for i=0 to ubound(A)
iI2wbR http://blog.numino.net/
A(i)=c16to2(A(i))
L15691 http://blog.numino.net/
next
5pCQMB http://blog.numino.net/
for i=0 to ubound(A)-1
RAOV9g http://blog.numino.net/
DigS=instr(A(i),"0")
exlHJj http://blog.numino.net/
Unicode=""
VlRFym http://blog.numino.net/
for j=1 to DigS-1
eShAkO http://blog.numino.net/
if j=1 then
j5U4mc http://blog.numino.net/
A(i)=right(A(i),len(A(i))-DigS)
5bKXPC http://blog.numino.net/
Unicode=Unicode & A(i)
G2rVTT http://blog.numino.net/
else
H8M4R1 http://blog.numino.net/
i=i+1
V6lyG4 http://blog.numino.net/
A(i)=right(A(i),len(A(i))-2)
kBo4yI http://blog.numino.net/
Unicode=Unicode & A(i)
fMi9Vi http://blog.numino.net/
end if
KxdRww http://blog.numino.net/
next
FdEkft http://blog.numino.net/
if len(c2to16(Unicode))=4 then
7dLSLg http://blog.numino.net/
ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode)))
BqKpbJ http://blog.numino.net/
else
5XPNVm http://blog.numino.net/
ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode)))
a1Nw2B http://blog.numino.net/
end if
jdCGOe http://blog.numino.net/
next
0pRzim http://blog.numino.net/
end function
u65sfA http://blog.numino.net/
function c2to16(x)
9RnCoz http://blog.numino.net/
i=1
f32521 http://blog.numino.net/
for i=1 to len(x) step 4
rU0T8Q http://blog.numino.net/
c2to16=c2to16 & hex(c2to10(mid(x,i,4)))
958paa http://blog.numino.net/
next
33U3B3 http://blog.numino.net/
end function
m7EwdP http://blog.numino.net/
function c2to10(x)
N8Kj7p http://blog.numino.net/
c2to10=0
5cPuMa http://blog.numino.net/
if x="0" then exit function
5V7AGU http://blog.numino.net/
i=0
ZNlvRS http://blog.numino.net/
for i= 0 to len(x) -1
LVZ5ue http://blog.numino.net/
if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
fae70M http://blog.numino.net/
next
h4iBfX http://blog.numino.net/
end function
DPDcH7 http://blog.numino.net/
function c16to2(x)
AWnzNC http://blog.numino.net/
i=0
Ql5b4m http://blog.numino.net/
for i=1 to len(trim(x))
2WLpYb http://blog.numino.net/
tempstr= c10to2(cint(int("&h" & mid(x,i,1))))
vo26i8 http://blog.numino.net/
do while len(tempstr)<4
rtO54K http://blog.numino.net/
tempstr="0" & tempstr
O4PsKn http://blog.numino.net/
loop
JZAB9I http://blog.numino.net/
c16to2=c16to2 & tempstr
7kyUlY http://blog.numino.net/
next
0VqjJy http://blog.numino.net/
end function
PoU5s4 http://blog.numino.net/
function c10to2(x)
UxK32E http://blog.numino.net/
mysign=sgn(x)
kK2Kxf http://blog.numino.net/
x=abs(x)
z07Epj http://blog.numino.net/
DigS=1
yEizvD http://blog.numino.net/
do
C0zR99 http://blog.numino.net/
if x<2^DigS then
n4r62t http://blog.numino.net/
exit do
88CJA4 http://blog.numino.net/
else
KTdYB1 http://blog.numino.net/
DigS=DigS+1
QwbhYD http://blog.numino.net/
end if
WzG8OU http://blog.numino.net/
loop
hVMzQe http://blog.numino.net/
tempnum=x
iUNRJp http://blog.numino.net/
i=0
4q0Hag http://blog.numino.net/
for i=DigS to 1 step-1
w44ukY http://blog.numino.net/
if tempnum>=2^(i-1) then
II2v95 http://blog.numino.net/
tempnum=tempnum-2^(i-1)
GS5Spl http://blog.numino.net/
c10to2=c10to2 & "1"
yot4zv http://blog.numino.net/
else
ypvA60 http://blog.numino.net/
c10to2=c10to2 & "0"
jqJy3D http://blog.numino.net/
end if
5G5djK http://blog.numino.net/
next
aeH1RO http://blog.numino.net/
if mysign=-1 then c10to2="-" & c10to2
WY8PPB http://blog.numino.net/
end function
N8SDMx http://blog.numino.net/
%>
Jtry4j http://blog.numino.net/
-----------------------------------------------------------------------------------------------------------------------------
ewW47D http://blog.numino.net/
ASP编码转换函数GB2312转换UTF-8
549M7E http://blog.numino.net/
<%
lvfw0K http://blog.numino.net/
Function chinese2unicode(Str)
bGhBie http://blog.numino.net/
dim i
QPfswj http://blog.numino.net/
dim Str_one
vHzGVB http://blog.numino.net/
dim Str_unicode
IBoQat http://blog.numino.net/
For i=1 to len(Str)
JGLOUR http://blog.numino.net/
Str_one=Mid(Str,i,1)
mWodHA http://blog.numino.net/
Str_unicode=Str_unicode&chr(38)
OvZN6E http://blog.numino.net/
Str_unicode=Str_unicode&chr(35)
4gW0lk http://blog.numino.net/
Str_unicode=Str_unicode&chr(120)
M8Lj7y http://blog.numino.net/
Str_unicode=Str_unicode& Hex(ascw(Str_one))
267WRI http://blog.numino.net/
Str_unicode=Str_unicode&chr(59)
Rxz6Ab http://blog.numino.net/
Next
l5vV2W http://blog.numino.net/
chinese2unicode = Str_unicode
39IiZh http://blog.numino.net/
End Function
gl5HJ5 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
cXcrGE http://blog.numino.net/
Response.Write ("<body onload=""document.form1.a.focus();"">")& vbCrlf
104xkI http://blog.numino.net/
action = Request.QueryString("action")
dG04JF http://blog.numino.net/
Select Case action
ZLL6X4 http://blog.numino.net/
Case "do"
EPpbcj http://blog.numino.net/
Call doing()
98eO6O http://blog.numino.net/
Case else
PY2Ff0 http://blog.numino.net/
Call mains()
mk0c10 http://blog.numino.net/
End Select
5kYYMi http://blog.numino.net/
'-----------------------------
j9H7rI http://blog.numino.net/
Sub mains()
VtZbPJ http://blog.numino.net/
Response.write "<fieldset style=""width:60%"" align=""center""><legend>Gb2312 - Utf-8</legend>"& vbCrlf
p0Ud5Y http://blog.numino.net/
Response.Write ("<form name=""form1"" method=post action='?action=do'><div align=center>")& vbCrlf
NnxeLk 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
cndJc9 http://blog.numino.net/
Response.Write ("<div align=center><textarea id='b' style='width:99%' rows='8'></textarea><br></div>")& vbCrlf
QAAsDC http://blog.numino.net/
Response.Write ("<br> <input type='submit' value='开始转换'></form></fieldset>")& vbCrlf
6Sremv http://blog.numino.net/
End Sub
uTRLr9 http://blog.numino.net/
'-----------------------------
5vAJzx http://blog.numino.net/
Sub doing()
j8TqbZ http://blog.numino.net/
Response.write "<fieldset style=""width:60%"" align=""center""><legend>Gb2312 - Utf-8</legend>"& vbCrlf
jVs4rY http://blog.numino.net/
Response.Write ("<form name=""form1"" method=post action='?action=do'><div align=center>")& vbCrlf
8j63St 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
uoL3S2 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
bontNL http://blog.numino.net/
Response.Write ("<br> <input type='submit' value='开始转换'></form></fieldset>")& vbCrlf
u3fHl5 http://blog.numino.net/
Response.Write ("<script>document.getElementById('b').innerHTML='"&server.htmlencode(chinese2unicode(Request.Form("a")))&"';")& vbCrlf
F9PlkB http://blog.numino.net/
Response.Write ("function docopy(){")& vbCrlf
5rakQX http://blog.numino.net/
Response.Write ("document.getElementById('b').select();")& vbCrlf
3onXI3 http://blog.numino.net/
Response.Write ("js = document.getElementById('b').createTextRange();")& vbCrlf
mKgR9K http://blog.numino.net/
Response.Write ("js.execCommand('Copy');")& vbCrlf
02I8eX http://blog.numino.net/
Response.Write ("document.getElementById('a').value='';")& vbCrlf
3IgbWo http://blog.numino.net/
Response.Write ("document.form1.submit();}")& vbCrlf
FqXPK3 http://blog.numino.net/
Response.Write ("</script>")& vbCrlf
ZomC0a http://blog.numino.net/
End Sub
452O0b http://blog.numino.net/
%>
更多相关内容...>>ASP字符转换:UTF-8与GB2312互转

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

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