Available GB2312 UTF-8 encoding functions

Source: Internet
Author: User
Tags end functions interface
Coding | function |gb2312|utf-8

Today, we are doing a mobile phone messaging interface to clients, because the interface of the SMS service provider only supports the Chinese UTF-8 encoding way, and the customer's website is GB2312 code, the page that uses UTF-8 can send a text message normally, but think of such two kinds of code separate, to the integration of the website system is still very convenient, Try a lot of code, and finally debug out of this GB2312 to UTF-8 encoded functions, share out to everyone.

' Chinese SMS UTF-8 Code
Private Function GBtoUTF8 (szinput)
Dim WCh, Uch, Szret
Dim x
Dim NASC, NASC2, NASC3
If szinput = "" Then
gbtoutf8= Szinput
Exit Function
End If
For x = 1 to Len (szinput)
WCH = Mid (Szinput, X, 1)
NASC = AscW (WCH)
If NASC < 0 Then NASC = nasc + 65536
If (NASC and &hff80) = 0 Then
Szret = Szret & WCH
Else
If (NASC and &hf000) = 0 Then
Uch = "%" & Hex ((NASC \ 2 ^ 6)) Or &hc0) & Hex (NASC and &h3f Or &h80)
Szret = Szret & Uch
Else
Uch = "%" & Hex (NASC \ 2 ^) Or &he0) & "%" & _
Hex (NASC \ 2 ^ 6) and &h3f Or &h80) & "%" & _
Hex (NASC and &h3f Or &h80)
Szret = Szret & Uch
End If
End If
Next
gbtoutf8= Szret
End Function



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.