vb 读取unicode 乱码

rgbcn rgbcn 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
¡Hola! nº 是西班牙文
¡Hola! nº 保存成.txt 编码为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
...全文
评论 7
收藏 已收藏
分享
返回顶部
rgbcn
VB基础类 7,788 成员 197,583 内容