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