- 帖子
- 22
- 主題
- 17
- 精華
- 0
- 積分
- 51
- 點名
- 0
- 作業系統
- wiindows
- 軟體版本
- Office 2010
- 閱讀權限
- 20
- 性別
- 男
- 來自
- 新北
- 註冊時間
- 2021-6-21
- 最後登錄
- 2022-1-4
|
網路上找到 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 |
|