Implement UTF8 conversion GB2312 GB code-application skills

Source: Internet
Author: User
Tags trim
Copy Code code as follows:

' Personal Code style note (the first lowercase alphabet in the variable name represents the variable type)
' I: an integer type;
' s: string;
Function U2utf8 (Byval a_inum)
Dim Sresult,sutf8
Dim Itemp,ihexnum,i

Ihexnum = Trim (a_inum)

If ihexnum = "" Then
Exit Function
End If

Sresult = ""

If (Ihexnum < 128) Then
Sresult = Sresult & Ihexnum
ElseIf (Ihexnum < 2048) Then
Sresult = ChrB (&h80 + (Ihexnum and &h3f))
Ihexnum = ihexnum \ &h40
Sresult = ChrB (&hc0 + ihexnum and &h1f)) & Sresult
ElseIf (Ihexnum < 65536) Then
Sresult = ChrB (&h80 + (Ihexnum and &h3f))
Ihexnum = ihexnum \ &h40
Sresult = ChrB (&h80 + ihexnum and &h3f)) & Sresult
Ihexnum = ihexnum \ &h40
Sresult = ChrB (&he0 + ihexnum and &AMP;HF)) & Sresult
End If

U2utf8 = Sresult
End Function

Function Gb2utf (Byval a_sstr)
Dim sgb,sresult,stemp
Dim Ilen,iunicode,itemp,i

SGB = Trim (A_SSTR)
Ilen = Len (SGB)
For i = 1 to Ilen
Stemp = Mid (sgb,i,1)
itemp = ASC (stemp)

If (itemp>127 OR itemp<0) Then
Iunicode = AscW (stemp)
If iunicode<0 Then
Iunicode = Iunicode + 65536
End If
Else
Iunicode = itemp
End If

Sresult = Sresult & U2utf8 (Iunicode)
Next

Gb2utf = Sresult
End Function

' Invoke method
Response.BinaryWrite (Gb2utf ("Chinese"))

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.