ASP字符转换:UTF-8与GB2312互转 |
UTF-8转GB2312函数 g2UA2N http://blog.numino.net/ <% 1803T3 http://blog.numino.net/ '用途:將UTF-8編碼漢字轉換為GB2312碼,兼容英文和數字 QaFd74 http://blog.numino.net/ '版權:雖說是原創,其實也參考了別人的部分算法 r8MHjN 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") T13Mp2 http://blog.numino.net/ function UTF2GB(UTFStr) 8uSYvW http://blog.numino.net/ for Dig=1 to len(UTFStr) lJ0fdw http://blog.numino.net/ if mid(UTFStr,Dig,1)="%" then vwN8B5 http://blog.numino.net/ if len(UTFStr) >= Dig+8 then 1o9q0q http://blog.numino.net/ GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9)) 10w1FY http://blog.numino.net/ Dig=Dig+8 0TO316 http://blog.numino.net/ else Mu00nN http://blog.numino.net/ GBStr=GBStr & mid(UTFStr,Dig,1) n7ZVA3 http://blog.numino.net/ end if tHw4vN http://blog.numino.net/ else LeB23o http://blog.numino.net/ GBStr=GBStr & mid(UTFStr,Dig,1) NHGv42 http://blog.numino.net/ end if WACunP http://blog.numino.net/ next 2hu4ms http://blog.numino.net/ UTF2GB=GBStr THBK1r http://blog.numino.net/ end function RhaaUG http://blog.numino.net/ function ConvChinese(x) MhSTF9 http://blog.numino.net/ A=split(mid(x,2),"%") DvxNGh http://blog.numino.net/ i=0 7QSFuC http://blog.numino.net/ j=0 9vU2N0 http://blog.numino.net/ for i=0 to ubound(A) L528Qj http://blog.numino.net/ A(i)=c16to2(A(i)) JsP44T http://blog.numino.net/ next qf1Cwe http://blog.numino.net/ for i=0 to ubound(A)-1 QpV8IB http://blog.numino.net/ DigS=instr(A(i),"0") 7gtP7i http://blog.numino.net/ Unicode="" BWZwS5 http://blog.numino.net/ for j=1 to DigS-1 5fu272 http://blog.numino.net/ if j=1 then yiRRv9 http://blog.numino.net/ A(i)=right(A(i),len(A(i))-DigS) nZME2N http://blog.numino.net/ Unicode=Unicode & A(i) CbW0U7 http://blog.numino.net/ else nONp2m http://blog.numino.net/ i=i+1 IO8H8q http://blog.numino.net/ A(i)=right(A(i),len(A(i))-2) Zgkf0P http://blog.numino.net/ Unicode=Unicode & A(i) SLujSs http://blog.numino.net/ end if mcxWAu http://blog.numino.net/ next eEAuOG http://blog.numino.net/ if len(c2to16(Unicode))=4 then h5poWb http://blog.numino.net/ ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode))) 4X0Bel http://blog.numino.net/ else yIzuyi http://blog.numino.net/ ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode))) 3xFcUy http://blog.numino.net/ end if lz7x3n http://blog.numino.net/ next Gyr0I4 http://blog.numino.net/ end function MGW8bu http://blog.numino.net/ function c2to16(x) 1j1bJo http://blog.numino.net/ i=1 B7sV3o http://blog.numino.net/ for i=1 to len(x) step 4 bh0i1R http://blog.numino.net/ c2to16=c2to16 & hex(c2to10(mid(x,i,4))) LhaEaD http://blog.numino.net/ next 18UDpb http://blog.numino.net/ end function p0z5s2 http://blog.numino.net/ function c2to10(x) DI70E7 http://blog.numino.net/ c2to10=0 TtCx50 http://blog.numino.net/ if x="0" then exit function I9L0Cw http://blog.numino.net/ i=0 xo1iIE http://blog.numino.net/ for i= 0 to len(x) -1 u82ZqY http://blog.numino.net/ if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i) nT9Gw8 http://blog.numino.net/ next 7821Ql http://blog.numino.net/ end function bQHmVu http://blog.numino.net/ function c16to2(x) 6CQtp0 http://blog.numino.net/ i=0 je77Dt http://blog.numino.net/ for i=1 to len(trim(x)) G2ae65 http://blog.numino.net/ tempstr= c10to2(cint(int("&h" & mid(x,i,1)))) 22JUqp http://blog.numino.net/ do while len(tempstr)<4 Ah8ryM http://blog.numino.net/ tempstr="0" & tempstr eIyhpK http://blog.numino.net/ loop tLJZzg http://blog.numino.net/ c16to2=c16to2 & tempstr 7NS9J6 http://blog.numino.net/ next pljtf7 http://blog.numino.net/ end function kP2St1 http://blog.numino.net/ function c10to2(x) cD3fVN http://blog.numino.net/ mysign=sgn(x) 7Za3UK http://blog.numino.net/ x=abs(x) nN858X http://blog.numino.net/ DigS=1 pGUpM1 http://blog.numino.net/ do KGF7od http://blog.numino.net/ if x<2^DigS then 6MYdEC http://blog.numino.net/ exit do YR6D8c http://blog.numino.net/ else 3tda7s http://blog.numino.net/ DigS=DigS+1 xMQy2f http://blog.numino.net/ end if 9y8vd8 http://blog.numino.net/ loop lCUv47 http://blog.numino.net/ tempnum=x A95nUs http://blog.numino.net/ i=0 b4mD10 http://blog.numino.net/ for i=DigS to 1 step-1 av0wX4 http://blog.numino.net/ if tempnum>=2^(i-1) then C3SDSn http://blog.numino.net/ tempnum=tempnum-2^(i-1) 3hgV6P http://blog.numino.net/ c10to2=c10to2 & "1" E73KO0 http://blog.numino.net/ else cBDje9 http://blog.numino.net/ c10to2=c10to2 & "0" X87Gov http://blog.numino.net/ end if 2Z8Vv6 http://blog.numino.net/ next 9143X1 http://blog.numino.net/ if mysign=-1 then c10to2="-" & c10to2 A0BoTI http://blog.numino.net/ end function 1XK3iI http://blog.numino.net/ %> iK7V7I http://blog.numino.net/ ----------------------------------------------------------------------------------------------------------------------------- 6I3l1b http://blog.numino.net/ ASP编码转换函数GB2312转换UTF-8 O1h9i7 http://blog.numino.net/ <% iPsd7F http://blog.numino.net/ Function chinese2unicode(Str) 0zpPO0 http://blog.numino.net/ dim i YA7l2N http://blog.numino.net/ dim Str_one m47eQo http://blog.numino.net/ dim Str_unicode km6Yjb http://blog.numino.net/ For i=1 to len(Str) 6eXWW3 http://blog.numino.net/ Str_one=Mid(Str,i,1) EOebya http://blog.numino.net/ Str_unicode=Str_unicode&chr(38) 7uvejV http://blog.numino.net/ Str_unicode=Str_unicode&chr(35) RBkh5e http://blog.numino.net/ Str_unicode=Str_unicode&chr(120) OxE1v7 http://blog.numino.net/ Str_unicode=Str_unicode& Hex(ascw(Str_one)) 3ZE0rZ http://blog.numino.net/ Str_unicode=Str_unicode&chr(59) DHkwMK http://blog.numino.net/ Next NHf16S http://blog.numino.net/ chinese2unicode = Str_unicode JvQ823 http://blog.numino.net/ End Function xOthX3 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 57XAKt http://blog.numino.net/ Response.Write ("<body onload=""document.form1.a.focus();"">")& vbCrlf Xwz0T2 http://blog.numino.net/ action = Request.QueryString("action") Q8KDG2 http://blog.numino.net/ Select Case action tptcnx http://blog.numino.net/ Case "do" oWEZ8B http://blog.numino.net/ Call doing() gAFLf1 http://blog.numino.net/ Case else 5JSq1G http://blog.numino.net/ Call mains() xqPkXl http://blog.numino.net/ End Select 9f5jRV http://blog.numino.net/ '----------------------------- 1eC8SM http://blog.numino.net/ Sub mains() 9TA1YA http://blog.numino.net/ Response.write "<fieldset style=""width:60%"" align=""center""><legend>Gb2312 - Utf-8</legend>"& vbCrlf QjV99b http://blog.numino.net/ Response.Write ("<form name=""form1"" method=post action='?action=do'><div align=center>")& vbCrlf 1g6zA3 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 Wotkz8 http://blog.numino.net/ Response.Write ("<div align=center><textarea id='b' style='width:99%' rows='8'></textarea><br></div>")& vbCrlf zhljp6 http://blog.numino.net/ Response.Write ("<br> <input type='submit' value='开始转换'></form></fieldset>")& vbCrlf n41ilp http://blog.numino.net/ End Sub SC7gic http://blog.numino.net/ '----------------------------- AlD0UX http://blog.numino.net/ Sub doing() tB8m2q http://blog.numino.net/ Response.write "<fieldset style=""width:60%"" align=""center""><legend>Gb2312 - Utf-8</legend>"& vbCrlf DY2gMz http://blog.numino.net/ Response.Write ("<form name=""form1"" method=post action='?action=do'><div align=center>")& vbCrlf Ehq5fD 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 F93QmE 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 6I9h9T http://blog.numino.net/ Response.Write ("<br> <input type='submit' value='开始转换'></form></fieldset>")& vbCrlf MszH1q http://blog.numino.net/ Response.Write ("<script>document.getElementById('b').innerHTML='"&server.htmlencode(chinese2unicode(Request.Form("a")))&"';")& vbCrlf 7zcP8Z http://blog.numino.net/ Response.Write ("function docopy(){")& vbCrlf 6bTDcD http://blog.numino.net/ Response.Write ("document.getElementById('b').select();")& vbCrlf 2od6MP http://blog.numino.net/ Response.Write ("js = document.getElementById('b').createTextRange();")& vbCrlf KALK1T http://blog.numino.net/ Response.Write ("js.execCommand('Copy');")& vbCrlf Z8slql http://blog.numino.net/ Response.Write ("document.getElementById('a').value='';")& vbCrlf 429NP6 http://blog.numino.net/ Response.Write ("document.form1.submit();}")& vbCrlf 5EpXzt http://blog.numino.net/ Response.Write ("</script>")& vbCrlf 90yMyD http://blog.numino.net/ End Sub p9Nx38 http://blog.numino.net/ %>
|
|