asp如何转换gb2312字符串为utf-8字符串

来源:百度知道 编辑:UC知道 时间:2024/05/28 09:40:16
如题,我的ASP程序要同时接受utf-8和gb2312的参数,程序是utf-8的,接收utf-8正常,但接收gb2312就无法工作,有没有什么办法能把gb2312字符参数转换成utf-8的,如果能自动判断更好

请不要到网上COPY一大堆过来,我已经找过了,但没找到满意的答案

解决问题的继续加分
我试了一下,好像还是有问题,我接受的是已经经过编码的字符,比如中国的utf-8编码:%E4%B8%AD%E5%9B%BD

写一个程序将gb码转换成UTF8, 以下是我用的函数
使用方法: UTF8STR = GB2UTF("GB码内容", 1)

不过我不能理解,你是怎么接收到gb码参数的? 无论是POST还是GET 如果你的页面写好是utf-8, 那你收到的参数应该都是UTF8的编码,难道你整个WEB的页面编码不统一吗?

Private Function GetHex(ByVal str1 As String, IsANSI As Boolean) As String
Dim b1() As Byte
If IsANSI Then b1 = StrConv(str1, vbFromUnicode) Else b1 = str1
Dim s1 As Long, n1 As Long, l1 As Long
l1 = LBound(b1)
n1 = UBound(b1) - l1 + 1
GetHex = Space(n1 * 2)
For s1 = 1 To n1
Mid(GetHex, s1 + s1 - 1, 2) = Replace(Format(Hex(b1(s1 + l1 - 1)), "@@"), " ", "0")
Next
End Function

Private Function U2UTF8(ByVal a_iNum, ByVal is_With_%)
Dim sResult, sTmpResult, caHex, sUTF8
Dim iTemp, iHexNum, i

iHexNum = a_iNum

If iHexNum = "" Then
Exit Function
End If

caHex = ""
sResult = ""