并非SQLite的乱码。windows的命令行console窗口只支持GBK的汉字。。
创新互联主要从事成都网站设计、成都网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务琼山,10多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792
数据库内容为unicode/utf8/utf16等其他汉字编码时,将不能在win命令行窗口显示正确。
建一个console.bat文件,写上
chcp 65001
cmd
然后建一个快捷方式到这个文件,把快捷方式的字体改成宋体
然后就可以使用sqlite命令并显示utf-8的内容
或者,库中的文字也用GBK编码,就可直接显示。
GBK编码与Unicode编码“兼容”,应该说它们的编码是一致的吧?
也就是说你转换出的Unicode编码就是你要的GBK编码呀。
如果要转换成你要的这种“格式”的Unicode编码,For循环中没必要用If去判断。
这样就行了:
strTemp = ""
For i = 1 To Len(aa)
strTemp = strTemp Right$("0000" Hex$(AscW((Mid$(aa, i, 1)))), 4)
Next
Text2.Text = strTemp
vb 怎么把汉字转换成gbk编码参考方法如下:面的两段VB代码分别针对UTF-8(UTF8EncodeURI)和GB2312(GBKEncodeURI)进行了编码的转换。Private Sub command1_click()Debug.Print (UTF8EncodeURI("汉字"))Debug.Print (GBKEncodeURI("汉字"))End SubFunction UTF8EncodeURI(szInput)Dim wch, uch, szRetDim xDim nAsc, nAsc2, nAsc3If szInput = "" ThenUTF8EncodeURI = szInputExit FunctionEnd IfFor x = 1 To Len(szInput)wch = Mid(szInput, x, 1)nAsc = AscW(wch)If nAsc 0 Then nAsc = nAsc + 65536If (nAsc And HFF80) = 0 ThenszRet = szRet wchElseIf (nAsc And HF000) = 0 Thenuch = "%" Hex(((nAsc \ 2 ^ 6)) Or HC0) Hex(nAsc And H3F Or H80)szRet = szRet uchElseuch = "%" Hex((nAsc \ 2 ^ 12) Or HE0) "%" _Hex((nAsc \ 2 ^ 6) And H3F Or H80) "%" _Hex(nAsc And H3F Or H80)szRet = szRet uchEnd IfEnd IfNextUTF8EncodeURI = szRetEnd FunctionFunction GBKEncodeURI(szInput)Dim i As LongDim x() As ByteDim szRet As StringszRet = ""x = StrConv(szInput, vbFromUnicode)For i = LBound(x) To UBound(x)szRet = szRet "%" Hex(x(i))NextGBKEncodeURI = szRetEnd Function
字符编码转换吗?
1.字符与gb2312(gbk的子集):
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) '字符以及字符串在vb2008中都是以unicode编码存储的
endIndex = x.Length - 1
For i = startIndex To endIndex
ret_GBKEncode = "%" Hex(x(i))
Next
Return ret_GBKEncode
End Function
'GBK解码
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
'转化为字节码
For i As Integer = 1 To n
sBytes(i - 1) = CByte("H" sInput.Substring(2 * i - 2, 2))
Next
'将字节码转化为字符串
ret_GBKDecode = System.Text.Encoding.Default.GetString(sBytes)
Return ret_GBKDecode
End Function
2.Unicode字符串为UTF-8
Imports System.Text
Public Function StringAsUtf8Bytes(ByVal strData As String) As Byte()
Dim bytes() As Byte
bytes = Encoding.UTF8.GetBytes(strData)
Return bytes
End Function
'这里可以类推出好几种。
用StrConv(String,vbUnicode,LCID)
String就是被转换的字符,LCID为H404(Big5),LCID为H804(GBK)