标题:gb2312编码转化成UTF-8编码的问题
只看楼主
zdloveday
Rank: 2
等 级:论坛游民
帖 子:221
专家分:96
注 册:2008-9-5
结帖率:68.89%
 问题点数:0 回复次数:0 
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&""))页面显示的不一样。请各位帮帮忙
搜索更多相关主题的帖子: 数据库 网上 
2013-09-18 16:25



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-420737-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049092 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved