返回列表 上一主題 發帖

[轉貼] vb 讀取unicode

[轉貼] vb 讀取unicode

網路上找到 vb 讀取unicode 的方法

Dim textBytes() As Byte, headBytes(2) As Byte
   fn = App.Path & "\test.txt"
If Dir(fn) = "" Then
MsgBox "文件不存在,請先按一下【寫入】按鈕生成“MyUnicode.txt”文件。", vbInformation
   Exit Sub
  End If
   Open fn For Binary As #1
       Get #1, , headBytes()  '讀取文件頭。
    Close #1
  If headBytes(0) = 255 And headBytes(1) = 254 Then '是Unicode編碼。十六進位為:FF 、FE。
     Open fn For Binary As #1
     ReDim textBytes(LOF(1) - 2) '減去文件頭佔用的2個位元組。
     Get #1, 3, textBytes()  '第三個位元組起為文本內容。
     Close #1
    Text1.Text = textBytes()  '在 VB 中字串是 UniCode 格式,所以Unicode碼直接賦值即可顯示文本內容。
     RichTextBox1.Text = textBytes()
Else
        MsgBox "非Unicode編碼,不予讀入,請按一下【寫入】按鈕。", vbInformation
End If
程式人員

        靜思自在 : 【是否發揮了良能?】人間壽命因為短暫,才更顯得珍貴。難得來一趟人間,應問是否為人間發揮了自己的良能,而不要一味求長壽。
返回列表 上一主題