| ASP字符转换:UTF-8与GB2312互转 |
UTF-8转GB2312函数 vORlSl http://blog.numino.net/ <% sDF4Wz http://blog.numino.net/ '用途:將UTF-8編碼漢字轉換為GB2312碼,兼容英文和數字 oqj483 http://blog.numino.net/ '版權:雖說是原創,其實也參考了別人的部分算法 JoIBo2 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") mJrc60 http://blog.numino.net/ function UTF2GB(UTFStr) 9nmCA5 http://blog.numino.net/ for Dig=1 to len(UTFStr) HvHuve http://blog.numino.net/ if mid(UTFStr,Dig,1)="%" then gaJ345 http://blog.numino.net/ if len(UTFStr) >= Dig+8 then 3oT8Ka http://blog.numino.net/ GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9)) 7wqzu3 http://blog.numino.net/ Dig=Dig+8 krZspy http://blog.numino.net/ else EArGEE http://blog.numino.net/ GBStr=GBStr & mid(UTFStr,Dig,1) xH3Ztl http://blog.numino.net/ end if 3zs53r http://blog.numino.net/ else uG133e http://blog.numino.net/ GBStr=GBStr & mid(UTFStr,Dig,1) N455FZ http://blog.numino.net/ end if jxw02Z http://blog.numino.net/ next 494pKE http://blog.numino.net/ UTF2GB=GBStr e06nP0 http://blog.numino.net/ end function R88m3a http://blog.numino.net/ function ConvChinese(x) AVsdT5 http://blog.numino.net/ A=split(mid(x,2),"%") 5fTx82 http://blog.numino.net/ i=0 Ztd86Z http://blog.numino.net/ j=0 Z0P002 http://blog.numino.net/ for i=0 to ubound(A) HA5SqH http://blog.numino.net/ A(i)=c16to2(A(i)) c21Gxa http://blog.numino.net/ next SsXmeF http://blog.numino.net/ for i=0 to ubound(A)-1 ZOBE8c http://blog.numino.net/ DigS=instr(A(i),"0") MqSVKJ http://blog.numino.net/ Unicode="" YMNtA2 http://blog.numino.net/ for j=1 to DigS-1 39i1eI http://blog.numino.net/ if j=1 then qvpmNR http://blog.numino.net/ A(i)=right(A(i),len(A(i))-DigS) 4Eh156 http://blog.numino.net/ Unicode=Unicode & A(i) 9m4zh3 http://blog.numino.net/ else EwzLKS http://blog.numino.net/ i=i+1 vc8oOH http://blog.numino.net/ A(i)=right(A(i),len(A(i))-2) 2KIAZx http://blog.numino.net/ Unicode=Unicode & A(i) qB8vDI http://blog.numino.net/ end if rxuKUs http://blog.numino.net/ next ZJ1s2o http://blog.numino.net/ if len(c2to16(Unicode))=4 then 87jggE http://blog.numino.net/ ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode))) mGPm2A http://blog.numino.net/ else enn4P1 http://blog.numino.net/ ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode))) qwS4bv http://blog.numino.net/ end if S2wbr8 http://blog.numino.net/ next 2Q24rN http://blog.numino.net/ end function 3r0p3J http://blog.numino.net/ function c2to16(x) uxc8hC http://blog.numino.net/ i=1 EYrD1G http://blog.numino.net/ for i=1 to len(x) step 4 zH85Ew http://blog.numino.net/ c2to16=c2to16 & hex(c2to10(mid(x,i,4))) PODeth http://blog.numino.net/ next UCaXCi http://blog.numino.net/ end function L8ABPf http://blog.numino.net/ function c2to10(x) Q9vQJI http://blog.numino.net/ c2to10=0 raPO0o http://blog.numino.net/ if x="0" then exit function NUnPHG http://blog.numino.net/ i=0 DXQnkV http://blog.numino.net/ for i= 0 to len(x) -1 Srd1Lu http://blog.numino.net/ if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i) U76cTQ http://blog.numino.net/ next DNv4PP http://blog.numino.net/ end function SwC6PN http://blog.numino.net/ function c16to2(x) NipH6A http://blog.numino.net/ i=0 10jh6J http://blog.numino.net/ for i=1 to len(trim(x)) 5fXHk0 http://blog.numino.net/ tempstr= c10to2(cint(int("&h" & mid(x,i,1)))) uI1182 http://blog.numino.net/ do while len(tempstr)<4 0kaMnG http://blog.numino.net/ tempstr="0" & tempstr 9l3xxQ http://blog.numino.net/ loop SAqJPr http://blog.numino.net/ c16to2=c16to2 & tempstr 1f43fC http://blog.numino.net/ next Oo9Ws8 http://blog.numino.net/ end function iPR46w http://blog.numino.net/ function c10to2(x) 1kwkrM http://blog.numino.net/ mysign=sgn(x) TwZDUn http://blog.numino.net/ x=abs(x) JK1bTx http://blog.numino.net/ DigS=1 ALXU0g http://blog.numino.net/ do jKNtLv http://blog.numino.net/ if x<2^DigS then LClyu3 http://blog.numino.net/ exit do R7oo14 http://blog.numino.net/ else 5V72D3 http://blog.numino.net/ DigS=DigS+1 MLP8y0 http://blog.numino.net/ end if s3i21Y http://blog.numino.net/ loop 075jhO http://blog.numino.net/ tempnum=x WU9pOb http://blog.numino.net/ i=0 zXd8Zc http://blog.numino.net/ for i=DigS to 1 step-1 UWVFNG http://blog.numino.net/ if tempnum>=2^(i-1) then p9pPZn http://blog.numino.net/ tempnum=tempnum-2^(i-1) 6yn1li http://blog.numino.net/ c10to2=c10to2 & "1" n35FsP http://blog.numino.net/ else txTZr4 http://blog.numino.net/ c10to2=c10to2 & "0" fkTh7j http://blog.numino.net/ end if Oomw3j http://blog.numino.net/ next 1NMvsD http://blog.numino.net/ if mysign=-1 then c10to2="-" & c10to2 FyoY7d http://blog.numino.net/ end function 9veYfj http://blog.numino.net/ %> TeNo76 http://blog.numino.net/ ----------------------------------------------------------------------------------------------------------------------------- s96UT1 http://blog.numino.net/ ASP编码转换函数GB2312转换UTF-8 Y7Gklm http://blog.numino.net/ <% EATw1X http://blog.numino.net/ Function chinese2unicode(Str) auwh3R http://blog.numino.net/ dim i TZklbL http://blog.numino.net/ dim Str_one bX5TJq http://blog.numino.net/ dim Str_unicode uFA97t http://blog.numino.net/ For i=1 to len(Str) F598aB http://blog.numino.net/ Str_one=Mid(Str,i,1) Gim39P http://blog.numino.net/ Str_unicode=Str_unicode&chr(38) 5cqOi8 http://blog.numino.net/ Str_unicode=Str_unicode&chr(35) vQ26uK http://blog.numino.net/ Str_unicode=Str_unicode&chr(120) E6Wiqv http://blog.numino.net/ Str_unicode=Str_unicode& Hex(ascw(Str_one)) 23U1XA http://blog.numino.net/ Str_unicode=Str_unicode&chr(59) llwc4D http://blog.numino.net/ Next aZPo0v http://blog.numino.net/ chinese2unicode = Str_unicode S2jmG8 http://blog.numino.net/ End Function giIDxV 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 iNS85N http://blog.numino.net/ Response.Write ("<body onload=""document.form1.a.focus();"">")& vbCrlf 7km59A http://blog.numino.net/ action = Request.QueryString("action") 1ZlCrf http://blog.numino.net/ Select Case action Hyi5EY http://blog.numino.net/ Case "do" 97vZMe http://blog.numino.net/ Call doing() 1xI7Wo http://blog.numino.net/ Case else qCEGWR http://blog.numino.net/ Call mains() XFX63D http://blog.numino.net/ End Select j0t9ME http://blog.numino.net/ '----------------------------- oGrq4o http://blog.numino.net/ Sub mains() o6vhEU http://blog.numino.net/ Response.write "<fieldset style=""width:60%"" align=""center""><legend>Gb2312 - Utf-8</legend>"& vbCrlf wOkqte http://blog.numino.net/ Response.Write ("<form name=""form1"" method=post action='?action=do'><div align=center>")& vbCrlf 4BlUis 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 3628h3 http://blog.numino.net/ Response.Write ("<div align=center><textarea id='b' style='width:99%' rows='8'></textarea><br></div>")& vbCrlf 8Fa9Sm http://blog.numino.net/ Response.Write ("<br> <input type='submit' value='开始转换'></form></fieldset>")& vbCrlf GR6FPg http://blog.numino.net/ End Sub xkn4ce http://blog.numino.net/ '----------------------------- k89fS1 http://blog.numino.net/ Sub doing() QuuyRu http://blog.numino.net/ Response.write "<fieldset style=""width:60%"" align=""center""><legend>Gb2312 - Utf-8</legend>"& vbCrlf 9SFyvD http://blog.numino.net/ Response.Write ("<form name=""form1"" method=post action='?action=do'><div align=center>")& vbCrlf dK6GtV 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 R4VGZV 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 On103F http://blog.numino.net/ Response.Write ("<br> <input type='submit' value='开始转换'></form></fieldset>")& vbCrlf 50m4aV http://blog.numino.net/ Response.Write ("<script>document.getElementById('b').innerHTML='"&server.htmlencode(chinese2unicode(Request.Form("a")))&"';")& vbCrlf k5FqTc http://blog.numino.net/ Response.Write ("function docopy(){")& vbCrlf AKNSgR http://blog.numino.net/ Response.Write ("document.getElementById('b').select();")& vbCrlf NV2HSZ http://blog.numino.net/ Response.Write ("js = document.getElementById('b').createTextRange();")& vbCrlf 6Vw0SJ http://blog.numino.net/ Response.Write ("js.execCommand('Copy');")& vbCrlf uxTR7U http://blog.numino.net/ Response.Write ("document.getElementById('a').value='';")& vbCrlf jd3bsW http://blog.numino.net/ Response.Write ("document.form1.submit();}")& vbCrlf SSNA7K http://blog.numino.net/ Response.Write ("</script>")& vbCrlf nnfcpC http://blog.numino.net/ End Sub 66Mfz6 http://blog.numino.net/ %>
|
|