并非SQLite的亂碼。windows的命令行console窗口只支持GBK的漢字。。
創(chuàng)新互聯(lián)主要從事成都網(wǎng)站設(shè)計、成都網(wǎng)站制作、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)瓊山,10多年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):13518219792
數(shù)據(jù)庫內(nèi)容為unicode/utf8/utf16等其他漢字編碼時,將不能在win命令行窗口顯示正確。
建一個console.bat文件,寫上
chcp 65001
cmd
然后建一個快捷方式到這個文件,把快捷方式的字體改成宋體
然后就可以使用sqlite命令并顯示utf-8的內(nèi)容
或者,庫中的文字也用GBK編碼,就可直接顯示。
GBK編碼與Unicode編碼“兼容”,應(yīng)該說它們的編碼是一致的吧?
也就是說你轉(zhuǎn)換出的Unicode編碼就是你要的GBK編碼呀。
如果要轉(zhuǎn)換成你要的這種“格式”的Unicode編碼,F(xiàn)or循環(huán)中沒必要用If去判斷。
這樣就行了:
strTemp?=?""
For?i?=?1?To?Len(aa)
strTemp?=?strTemp??Right$("0000"??Hex$(AscW((Mid$(aa,?i,?1)))),?4)
Next
Text2.Text?=?strTemp
vb 怎么把漢字轉(zhuǎn)換成gbk編碼參考方法如下:面的兩段VB代碼分別針對UTF-8(UTF8EncodeURI)和GB2312(GBKEncodeURI)進行了編碼的轉(zhuǎn)換。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
字符編碼轉(zhuǎn)換嗎?
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
'轉(zhuǎn)化為字節(jié)碼
For i As Integer = 1 To n
sBytes(i - 1) = CByte("H" sInput.Substring(2 * i - 2, 2))
Next
'將字節(jié)碼轉(zhuǎn)化為字符串
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就是被轉(zhuǎn)換的字符,LCID為H404(Big5),LCID為H804(GBK)