GB2312 is a subset of GBK encoding. Use the GBK encoding function.
'Gbk encoding (results are separated by percent signs %)
Public Function GBKEncode (ByVal sInput As String) As String
Dim ret_GBKEncode As String = ""
Dim I As Integer
Dim startIndex As Integer = 0
Dim endIndex As Integer
Dim x () As Byte = System. Text. Encoding. Default. GetBytes (sInput) 'characters and strings are stored in unicode Encoding in vb2008.
EndIndex = x. Length-1
For I = startIndex To endIndex
Ret_GBKEncode & = "%" & Hex (x (I ))
Next
Return ret_GBKEncode
End Function
'Gbk Decoding
Public Function GBKDecode (ByVal sInput As String) As String
SInput = sInput. Replace ("% ","")
Dim ret_GBKDecode As String = ""
Dim sLen As Integer = sInput. Length
Dim n As Integer = sLen \ 2
Dim sBytes (0 To n-1) As Byte
'Convert to bytecode
For I As Integer = 1 To n
SBytes (I-1) = CByte ("& H" & sInput. Substring (2 * I-2, 2 ))
Next
'Convert bytecode into a string
Ret_GBKDecode = System. Text. Encoding. Default. GetString (sBytes)
Return ret_GBKDecode
End Function