Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)

时间:2023-01-06 07:31:17

为了一个gb2312下post中文参数到utf-8页面的程序,随闷的难受,查了一下午资料,大部分是讲Gb2312传到Gb2312页面的UrlEncode,没有提供到Utf-8页面的UrlEncode,后来找到Unicode转Utf-8码的资料,参考之下,终于写出了Utf-8的UrlEncode,这里整理下各种UrlEncode方法,供有需要的朋友参考。

详细Utf-8编码规则请百度一下。

Unicode 与 Utf-8码间的内码规则模板为:
原始码(16进制) UTF-8编码(二进制)
--------------------------------------------
0000 - 007F       0xxxxxxx
0080 - 07FF       110xxxxx 10xxxxxx
0800 - FFFF       1110xxxx 10xxxxxx 10xxxxxx   (中文字在此区间)
……
--------------------------------------------

例如:
百度中查询“中国人”,会将中文URL参数转为Gb2312码的16进制表示,一个中文字用2个字节
http://www.baidu.com/s?wd=%D6%D0%B9%FA%C8%CB
Google中查询“中国人”,会将中文URL参数转为Utf-8编码的16进制表示,一个中文字用3个字节
http://www.google.cn/search?client=opera&rls=en&q=%E4%B8%AD%E5%9B%BD%E4%BA%BA&sourceid=opera&ie=utf-8&oe=utf-8

 

Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
' Url编码,Gb2312页面之间传递参数
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Function  URLEncode_Gb(ByVal str)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Dim  i,s
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Dim  B,bCode,gb,Hight8b,Low8b
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    s 
=   ""
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
For  i  =   1   To   Len (str)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        B 
=   Mid (str,i, 1 )
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        bCode
= Abs ( Asc (B))
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        
If  (bCode >= 48   And  bCode <= 57 Or  (bCode >= 65   And  bCode <= 90 Or  (bCode >= 97   And  bCode <= 122 Or  bCode = 42   Or  bCode = 45   Or  bCode = 46   Or  bCode = 64   Or  bCode = 95   Then  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)            
' 48 to 57代表0~9;65 to 90代表A~Z;97 to 122代表a~z
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
             ' 42代表*;46代表.;64代表@;45代表-;95代表_ 
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
            s = &  B
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        
ElseIf  bCode = 32   Then   ' 空格转成+
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
            s = &   " + "
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        
ElseIf  bCode < 128   Then      ' 低于128的Ascii转成1个字节
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
            s = &   " % "   &   Right ( " 00 "   &   Hex (bCode), 2 )
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        
Else  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)            gb 
=   Asc (B)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)            
If  gb  <   0   Then
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                gb 
=  gb  +   & H10000     ' gb编码为负数,要加上65536
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
             End   If
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)            Hight8b 
=  (gb   And   & HFF00)  /   & H100     ' 二进制高8位
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
            Low8b  =  gb  And   & HFF     ' 二进制低8位
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
            s  =  s  &   " % "   &   Hex (Hight8b)  &    " % "   &   Hex (Low8b)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        
End   If   
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Next
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    URLEncode_Gb 
=  s
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
End Function
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
' Url解码,Gb2312页面之间传递参数
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Function  URLDecode_Gb(ByVal str)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Dim  i,s
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Dim  B,bCode,gb,Hight8b,Low8b
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    s 
=   ""
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
For  i  =   1   To   Len (str)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        B 
=   Mid (str,i, 1 )
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        
Select   Case  B
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)            
Case   " + "
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                s
= &   "   "
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)            
Case   " % "
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                gb
= Mid (str,i + 1 , 2 )
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                bCode
= CInt ( " &H "   &  gb)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                
If  bCode < 128   Then
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                    i
= i + 2
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                
Else
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                    bCode
= CInt ( " &H "   &  gb  &   Mid (str,i + 4 , 2 ))
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                    i
= i + 5
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                
End   If  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                s
= &   Chr (bCode)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)            
Case   Else
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                s
= &  B
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        
End   Select  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Next
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    URLDecode_Gb 
=  s
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
End Function
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
' URL编码,Gb2312页面提交到Utf-8页面
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Function  UrlEncode_GBToUtf8(ByVal str)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Dim  B                     ' 单个字符
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
     Dim  ub                   ' 中文字的Unicode码(2字节)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
     Dim  High8b, Low8b        ' Unicode码的高低位字节
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
     Dim  UtfB1, UtfB2, UtfB3  ' Utf-8码的三个字节
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
     Dim  i, s
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
For  i  =   1   To   Len (str)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        B
= Mid (str, i,  1 )
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        ub 
=  AscW(B)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        
If  (ub >= 48   And  ub <= 57 Or  (ub >= 65   And  ub <= 90 Or  (ub >= 97   And  ub <= 122 Or  ub = 42   Or  ub = 45   Or  ub = 46   Or  ub = 64   Or  ub = 95   Then  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)            
' 48 to 57代表0~9;65 to 90代表A~Z;97 to 122代表a~z
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
             ' 42代表*;46代表.;64代表@;45代表-;95代表_ 
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
            s = &  B
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        
ElseIf  ub = 32   Then   ' 空格转成+
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
            s = &   " + "
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        
ElseIf  ub < 128   Then      ' 低于128的Ascii转成1个字节
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
            s = &   " % "   &   Right ( " 00 "   &   Hex (ub), 2 )
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        
Else
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)            High8b 
=  (ub  And   & HFF00)  /   & H100  ' Unicode码高位
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
            Low8b  =  ub  And   & HFF  ' Unicode码低位
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
            UtfB1  =  (High8b  And   & HF0)  /   & H10  Or   & HE0  ' 取Unicode高位字节的二进制的前4位 + 11100000
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
            UtfB2  =  ((High8b  And   & HF)  *   & H4  +  (Low8b  And   & HC0)  /   & H40)  Or   & H80  ' 取Unicode高位字节的后4位及低位字节的前2位 +10000000
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
            UtfB3  =  (Low8b  And   & H3F)  Or   & H80  ' 取Unicode低位字节的二进制后6位 + 10000000
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
            s  =  s  &   " % "   &   Hex (UtfB1)  &   " % "   &   Hex (UtfB2)  &   " % "   &   Hex (UtfB3)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        
End   If
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Next
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    UrlEncode_GBToUtf8 
=  s
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
End Function
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
' “汉”-AscW("汉")=27721(十进制)    01101100 01001001(二进制)     6C49(十六进制)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)'
将Gb2312码转成Utf-8码(十六进制表示)的方法为,先用AscW将Gb2312转为Unicode码(2字节),再'将Unicode码的二进制中的位按utf-8(3字节)模板规则填充 x 位:
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)

Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
' URL解码,Gb2312页面提交到Utf-8页面
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Function  UrlDecode_GBToUtf8(ByVal str)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Dim  B,ub     ' 中文字的Unicode码(2字节)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
     Dim  UtfB     ' Utf-8单个字节
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
     Dim  UtfB1, UtfB2, UtfB3  ' Utf-8码的三个字节
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
     Dim  i, n, s
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    n
= 0
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    ub
= 0
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
For  i  =   1   To   Len (str)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        B
= Mid (str, i,  1 )
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        
Select   Case  B
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)            
Case   " + "
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                s
= &   "   "
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)            
Case   " % "
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                ub
= Mid (str, i  +   1 2 )
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                UtfB 
=   CInt ( " &H "   &  ub)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                
If  UtfB < 128   Then  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                    i
= i + 2
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                    s
= &  ChrW(UtfB)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                
Else  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                    UtfB1
= (UtfB  And   & H0F)  *   & H1000     ' 取第1个Utf-8字节的二进制后4位
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
                    UtfB2 = ( CInt ( " &H "   &   Mid (str, i  +   4 2 ))  And   & H3F)  *   & H40         ' 取第2个Utf-8字节的二进制后6位
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
                    UtfB3 = CInt ( " &H "   &   Mid (str, i  +   7 2 ))  And   & H3F         ' 取第3个Utf-8字节的二进制后6位
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
                    s = &  ChrW(UtfB1  Or  UtfB2  Or  UtfB3)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                    i
= i + 8
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                
End   If  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)            
Case   Else      ' Ascii码
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
                s = &  B
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        
End   Select  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Next
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    UrlDecode_GBToUtf8 
=  s
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
End Function
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
' URL编码,Gb2312页面提交到Utf-8页面,另一种位计算方法
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Private   Function  UrlEncode_GBToUtf8_V2(szInput) 
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Dim  wch, uch, szRet 
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Dim  x 
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Dim  nAsc, nAsc2, nAsc3 
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
If  szInput  =   ""   Then  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        UrlEncode_GBToUtf8_V2
=  szInput 
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        
Exit   Function  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
End   If  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
For  x  =   1   To   Len (szInput) 
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        wch 
=   Mid (szInput, x,  1
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        nAsc 
=  AscW(wch) 
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        
If  nAsc  <   0   Then  nAsc  =  nAsc  +   65536  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        
If  (nAsc  And   & HFF80)  =   0   Then  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)            szRet 
=  szRet  &  wch 
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        
Else  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)            
If  (nAsc  And   & HF000)  =   0   Then  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                uch 
=   " % "   &   Hex (((nAsc    2   ^   6 ))  Or   & HC0)  &   Hex (nAsc  And   & H3F  Or   & H80) 
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                szRet 
=  szRet  &  uch 
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)            
Else  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                uch 
=   " % "   &   Hex ((nAsc    2   ^   12 Or   & HE0)  &   " % "   &  _ 
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                
Hex ((nAsc    2   ^   6 And   & H3F  Or   & H80)  &   " % "   &  _ 
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                
Hex (nAsc  And   & H3F  Or   & H80) 
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)                szRet 
=  szRet  &  uch 
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)            
End   If  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        
End   If  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Next  
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    UrlEncode_GBToUtf8_V2
=  szRet 
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
End Function
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
' VB下用API方法的Unicode转Utf-8方法:
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Private  Declare  Function  WideCharToMultiByte Lib  " kernel32 "  (ByVal CodePage  As   Long , ByVal dwFlags  As   Long , ByVal lpWideCharStr  As   Long , ByVal cchWideChar  As   Long , ByRef lpMultiByteStr  As  Any, ByVal cchMultiByte  As   Long , ByVal lpDefaultChar  As   String , ByVal lpUsedDefaultChar  As   Long As   Long
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Private  Declare  Function  MultiByteToWideChar Lib  " kernel32 "  (ByVal CodePage  As   Long , ByVal dwFlags  As   Long , ByVal lpMultiByteStr  As   Long , ByVal cchMultiByte  As   Long , ByVal lpWideCharStr  As   Long , ByVal cchWideChar  As   Long As   Long
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Private   Const  CP_UTF8  =   65001
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Function  Utf8ToUnicode(ByRef Utf()  As   Byte As   String
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Dim  lRet  As   Long
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Dim  lLength  As   Long
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Dim  lBufferSize  As   Long
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    lLength 
=   UBound (Utf)  -   LBound (Utf)  +   1
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
If  lLength  <=   0   Then   Exit   Function
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    lBufferSize 
=  lLength  *   2
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    Utf8ToUnicode 
=   String $(lBufferSize,  Chr ( 0 ))
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    lRet 
=  MultiByteToWideChar(CP_UTF8,  0 , VarPtr(Utf( 0 )), lLength, StrPtr(Utf8ToUnicode), lBufferSize)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
If  lRet  <>   0   Then
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)        Utf8ToUnicode 
=   Left (Utf8ToUnicode, lRet)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
End   If
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
End Function
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
Function  UnicodeToUtf8(ByVal UCS  As   String As   Byte ()
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Dim  lLength  As   Long
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Dim  lBufferSize  As   Long
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Dim  lResult  As   Long
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
Dim  abUTF8()  As   Byte
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    lLength 
=   Len (UCS)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
If  lLength  =   0   Then   Exit   Function
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    lBufferSize 
=  lLength  *   3   +   1
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
ReDim  abUTF8(lBufferSize  -   1 )
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    lResult 
=  WideCharToMultiByte(CP_UTF8,  0 , StrPtr(UCS), lLength, abUTF8( 0 ), lBufferSize, vbNullString,  0 )
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
If  lResult  <>   0   Then
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    lResult 
=  lResult  -   1
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
ReDim  Preserve abUTF8(lResult)
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    UnicodeToUtf8 
=  abUTF8
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)    
End   If
Gb2312及Gb2312转Utf-8编码的UrlEncode编码解码(全)
End Function