gb2312编码转化成UTF-8编码的问题
大家好我在网上找了一段代码 是把gb2313编码转化成utf-8的编码,因为我只转化一个字段然后再添加到数据库中,代码如下:Function U2UTF8(Byval a_iNum)
Dim sResult,sUTF8
Dim iTemp,iHexNum,i
iHexNum = Trim(a_iNum)
If iHexNum = "" Then
Exit Function
End If
sResult = ""
If (iHexNum < 128) Then
sResult = sResult & iHexNum
ElseIf (iHexNum < 2048) Then
sResult = ChrB(&H80 + (iHexNum And &H3F))
iHexNum = iHexNum \ &H40
sResult = ChrB(&HC0 + (iHexNum And &H1F)) & sResult
ElseIf (iHexNum < 65536) Then
sResult = ChrB(&H80 + (iHexNum And &H3F))
iHexNum = iHexNum \ &H40
sResult = ChrB(&H80 + (iHexNum And &H3F)) & sResult
iHexNum = iHexNum \ &H40
sResult = ChrB(&HE0 + (iHexNum And &HF)) & sResult
End If
U2UTF8 = sResult
End Function
Function GB2UTF(Byval a_sStr)
Dim sGB,sResult,sTemp
Dim iLen,iUnicode,iTemp,i
sGB = Trim(a_sStr)
iLen = Len(sGB)
For i = 1 To iLen
sTemp = Mid(sGB,i,1)
iTemp = Asc(sTemp)
If (iTemp>127 or iTemp<0) Then
iUnicode = AscW(sTemp)
If iUnicode<0 Then
iUnicode = iUnicode + 65536
End If
Else
iUnicode = iTemp
End If
sResult = sResult & U2UTF8(iUnicode)
Next
GB2UTF = sResult
End Function
下面是调用的方法
Response.BinaryWrite(GB2UTF(""&RK_HuoWu_Name&"")) 这里只能在页面显示出来转化后的utf-8编码
问题:我要的是RK_HuoWu_Name 这个字段 转码成(utf-8)后的值 因为我要添加到数据库中去。请问这个值要怎么写呢?
光写成 GB2UTF(""&RK_HuoWu_Name&"") 这样是不行的 跟Response.BinaryWrite(GB2UTF(""&RK_HuoWu_Name&""))页面显示的不一样。请各位帮帮忙