UTF-8 Unicode Ansi Chinese character GB2321 several code conversion programs _ Application Techniques

Source: Internet
Author: User
Tags abs
Today engaged in Sxna, encountered the problem of coding conversion, engaged in one hours, experienced hardships, finally summed up the following Chinese characters converted to various UTF-8 Unicode ANSI coding program. Do not dare to enjoy the exclusive, hereby dedicate to everyone programming enthusiasts!


--------------------------------------------------------------------------------
Matches Google's UTF code
Chinese characters go through encodeuricomponent into%e6%b1%89%e5%ad%97

%e6%b1%89%e5%ad%97 after decodeuricomponent into Chinese characters

Google search for "kanji":
http://www.google.com/search?hl=zh-CN&q=%E6%B1%89%E5%AD%97

UTF-8 code conforming to Baidu
Chinese characters go through ansicode into%ba%ba%d7%d6

Ba%ba%d7%d6 through Decodeansi into Chinese characters

Search "Chinese characters" with Baidu:
Http://www.baidu.com/baidu?word=%BA%BA%D7%D6


--------------------------------------------------------------------------------

Chinese characters changed into Chinese characters after Chinese2unicode

Chinese characters changed into Chinese characters after UTF2GB


--------------------------------------------------------------------------------

Test.asp the original procedure is as follows
(Download source program Http://www.dc9.cn/upload/test.rar)
Copy Code code as follows:

UTF-8 Unicode Ansi Chinese character GB2321 several encoding conversion programs

Today engaged in Sxna, encountered the problem of coding conversion, looking for one hours, experienced hardships, finally summed up the following Chinese characters converted to a variety of UTF-8 Unicode ANSI coding program. Do not dare to enjoy the exclusive, hereby dedicate to everyone programming enthusiasts!

<script language= "JAVASCRIPT" runat= "Server" >
var SS;
var DD;
Ss=decodeuricomponent ("%e6%b1%89%e5%ad%97");
Dd=encodeuricomponent ("Chinese characters");
</script>
Matches Google's UTF code
<p>
Chinese characters passed encodeURIComponent into
<%=dd%>
</p>
<p>
%e6%b1%89%e5%ad%97 through decodeuricomponent into
<%=ss%>
</p>


<script language= "VBScript" runat= "Server" >
Function Ansicode (Vstrin)
Dim I, Strreturn, Innercode, THISCHR
Dim Hight8, Low8
Strreturn = ""
For i = 1 to Len (Vstrin)
THISCHR = Mid (vstrin,i,1)
If Abs (ASC (THISCHR)) < &hff Then
Strreturn = Strreturn & THISCHR
Else
Innercode = ASC (THISCHR)
If Innercode < 0 Then
Innercode = Innercode + &h10000
End If
Hight8 = (Innercode and &hff00) \ &hff
Low8 = Innercode and &hff
Strreturn = strreturn & "%" & Hex (HIGHT8) & "%" & Hex (LOW8)
End If
Next
Ansicode = Strreturn
End Function

Function Decodeansi (s)
Dim I, STMP, Sresult, STMP1
Sresult = ""
For I=1 to Len (s)
If Mid (s,i,1) = "%" Then
STMP = "&h" & Mid (s,i+1,2)
If IsNumeric (STMP) Then
If CInt (STMP) =0 Then
i = i + 2
ElseIf CInt (STMP) >0 and CInt (STMP) <128
Sresult = Sresult & Chr (STMP)
i = i + 2
Else
If Mid (s,i+3,1) = "%" Then
STMP1 = "&h" & Mid (s,i+4,2)
If IsNumeric (STMP1) Then
Sresult = Sresult & Chr (CInt (STMP) *16*16 + CInt (STMP1))
i = i + 5
End If
Else
Sresult = Sresult & Chr (STMP)
i = i + 2
End If
End If
Else
Sresult = Sresult & Mid (s,i,1)
End If
Else
Sresult = Sresult & Mid (s,i,1)
End If
Next
Decodeansi = Sresult
End Function
</script>
UTF-8 code conforming to Baidu
<p>
Chinese characters passed Ansicode into
<%=ansicode ("kanji")%>
</p>
<p>
%ba%ba%d7%d6 through Decodeansi into
<%=decodeansi ("%ba%ba%d7%d6")%>
</p>

<%
' Kanji conversion to UTF-8
function Chinese2unicode (STR)
Dim i
Dim Str_one
Dim Str_unicode
For I=1 to Len (STR)
Str_one=mid (str,i,1)
STR_UNICODE=STR_UNICODE&AMP;CHR (38)
STR_UNICODE=STR_UNICODE&AMP;CHR (35)
STR_UNICODE=STR_UNICODE&AMP;CHR (120)
str_unicode=str_unicode& Hex (AscW (Str_one))
STR_UNICODE=STR_UNICODE&AMP;CHR (59)
Next
Chinese2unicode=str_unicode
End Function





' UTF-8 to GB2312

function UTF2GB (UTFSTR)
For Dig=1 to Len (UTFSTR)
If mid (utfstr,dig,1) = "%" Then
If Len (utfstr) >= dig+8 Then
Gbstr=gbstr & Convchinese (Mid (utfstr,dig,9))
Dig=dig+8
Else
Gbstr=gbstr & Mid (utfstr,dig,1)
End If
Else
Gbstr=gbstr & Mid (utfstr,dig,1)
End If
Next
Utf2gb=gbstr
End Function


function Convchinese (x)
A=split (Mid (x,2), "%")
I=0
J=0

For i=0 to UBound (A)
A (i) =c16to2 (A (i))
Next

For i=0 to UBound (A)-1
Digs=instr (A (i), "0")
Unicode= ""
For J=1 to DigS-1
If J=1 Then
A (i) =right (A (i), Len (A (i))-digs)
Unicode=unicode & A (i)
Else
I=i+1
A (i) =right (A (i), Len (A (i))-2)
Unicode=unicode & A (i)
End If
Next

If Len (c2to16 (Unicode)) =4 Then
Convchinese=convchinese & ChrW (int ("&h" & C2to16 (Unicode))
Else
Convchinese=convchinese & chr (int ("&h" & C2to16 (Unicode))
End If
Next
End Function

function c2to16 (x)
I=1
For I=1 to Len (x) Step 4
C2to16=c2to16 & Hex (C2to10 (Mid (x,i,4)))
Next
End Function

function C2to10 (x)
C2to10=0
If x= "0" Then Exit function
I=0
For i= 0 to Len (x)-1
If Mid (X,len (x)-i,1) = "1" then c2to10=c2to10+2^ (i)
Next
End Function

function C16to2 (x)
I=0
For I=1 to Len (Trim (x))
Tempstr= C10to2 (CInt (int ("&h" & Mid (x,i,1)))
Do While Len (TEMPSTR) <4
Tempstr= "0" & TempStr
Loop
C16to2=c16to2 & TempStr
Next
End Function

function C10to2 (x)
MYSIGN=SGN (x)
X=abs (x)
Digs=1
Todo
If X<2^digs Then
Exit Do
Else
Digs=digs+1
End If
Loop
Tempnum=x

I=0
For I=digs to 1 step-1
If tempnum>=2^ (i-1) Then
tempnum=tempnum-2^ (i-1)
C10to2=c10to2 & "1"
Else
C10to2=c10to2 & "0"
End If
Next
If Mysign=-1 then c10to2= "-" & C10to2
End Function
%>
<P> Chinese characters passed Chinese2unicode into
<%=chinese2unicode ("kanji")%> (need to see the source code, the browser has been directly translated)
</p>
<p> Chinese characters passed UTF2GB into
&LT;%=UTF2GB ("kanji")%> (need to see the source code, the browser has been directly translated)


In addition, a good code conversion station was found on the Internet.
http://www.dheart.net/bmzh/index.php

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.