VB中如何读取unicode格式码的txt文件,高手look

tubo_true 2007-01-09 01:29:08
VB引用Fso不管事,直接open ... as #1乱码

请问如何正确读取

高手指点
...全文
1604 36 打赏 收藏 转发到动态 举报
写回复
用AI写文章
36 条回复
切换为时间正序
请发表友善的回复…
发表回复
gooore 2011-06-17
  • 打赏
  • 举报
回复
好高的楼
VBAdvisor 2011-06-17
  • 打赏
  • 举报
回复

Public Function UnicodeFile_Read_VB(ByVal sFileName As String) As String

Dim FF As Long
Dim b() As Byte
Dim s As String

Const uBOM As String = "ÿþ"

On Error Resume Next

FF = FreeFile
Open sFileName For Binary Access Read As FF
ReDim b(LOF(FF))
Get FF, , b
Close FF
If b(0) = 255 And b(1) = 254 Then
s = b
Else
s = StrConv(b, vbUnicode) 'ANSI file
End If

UnicodeFile_Read_VB = s

End Function

Public Sub UnicodeFile_Write_VB(ByVal sFileName As String, _
ByVal vVar As String, _
Optional ByVal bInsertBOM As Boolean = True)

Dim FF As Long
Dim b() As Byte

On Error Resume Next
Kill sFileName
On Error GoTo 0
FF = FreeFile
Open sFileName For Binary Access Write As #FF
If bInsertBOM Then
ReDim b(1)
b(0) = &HFF
b(1) = &HFE
Put #FF, , b
Erase b
End If
b = vVar
Put #FF, , b
Close #FF
End Sub

laserw9 2011-06-17
  • 打赏
  • 举报
回复
等待答案!!!
tubo_true 2007-02-06
  • 打赏
  • 举报
回复
reply “我”在其他机器上则显示一个小框

那是因为,f8e1这个字,你save的时候用ansi了

在你save之前,肯定提示什么有unicode,保存丢失什么的。

用unicode存就行,utf-8我没试过。
VBAdvisor 2007-02-06
  • 打赏
  • 举报
回复
“我”在其他机器上则显示一个小框,不是问号(你说的对,不是“?”)
注意:在其他机器上(没有安装你创建的字符),则显示一个小框,在本机显示正确,为你所创建的字。
(完,不在回答,good luck!)
tubo_true 2007-02-05
  • 打赏
  • 举报
回复
'''''''''''''''''''''''''''''''''''''''''''''''''
因为你造的字在自己的电脑里,所以只能本机显示
'''''''''''''''''''''''''''''''''''''''''''''''''

这句话正确,但是如果换一台机器
他的确是显示不出来,但是他绝不应该显示问号??

用记事本保存 你unicode格式,你再试试

举例
a.txt 保存为unicode格式
内容是
“我们”

如果“我”是造的字的话
在其他机器上则应显示“ 门” 应以空格替代,而不应是问号

可以试试

VBAdvisor 2007-02-05
  • 打赏
  • 举报
回复
如果“我”是造的字的话
在其他机器上则应显示“ 门” 应以空格替代,而不应是问号

答:在你假设的条件下,“我”在其他机器上则显示一个小框,不是问号(你说的对,不是“?”)。问题是a.txt是Unicode或UTF-8文件吗?如果你Save成ANSI,那肯定是奇怪的乱码了。
VBAdvisor 2007-02-05
  • 打赏
  • 举报
回复
如果“我”是造的字的话
在其他机器上则应显示“ 门” 应以空格替代,而不应是问号

答:在你假设的条件下,“我”在其他机器上则显示一个小框,不是问号(你说的对,不是“?”)。问题是a.txt是Unicode或UTF-8文件吗?如果你Save成ANSI,那肯定是奇怪的乱码了。
VBAdvisor 2007-02-02
  • 打赏
  • 举报
回复
因为你造的字在自己的电脑里,所以只能本机显示。
当然你可以Copy你所造字体到其他的电脑里去显示。
说明:测试环境:XP (English)/SP2,VB6 (En) SP6.我用的是我自编的 DLL/TLB Extend Unicode TextBox和Unicode RichEdit (using CreateWindowExW)。
VBAdvisor 2007-02-02
  • 打赏
  • 举报
回复
看了你的帖很多天,还没解决,我就试了一下。可以呀,在Textbox和RichEdit中都可以看到。问题有可能是你没正确用eudcedit.exe,先选中F8E1--〉然后画--〉Save Character--->Font Links to link with all Font.
tubo_true 2007-02-02
  • 打赏
  • 举报
回复
是用造字程序 eudcedit.exe

自己造的字

sss2002 2007-02-01
  • 打赏
  • 举报
回复
是: “狲” 字吗?
tubo_true 2007-02-01
  • 打赏
  • 举报
回复
waiting...
tubo_true 2007-01-31
  • 打赏
  • 举报
回复
有 成功的吗?
hebhd 2007-01-30
  • 打赏
  • 举报
回复
没有办法解决..我做的时候直接用字节数组.
只要用 dim a as string 再赋值肯定会出错.不光这一个码位.

无可奈何的vb
fxs_2008 2007-01-29
  • 打赏
  • 举报
回复
我也遇到这个问题,open as 出现乱码,主要是由于各字符的编码不同引起的。
我查这不少文章,说window的编码是unicode.
而系统的编码好像是GB3212
但如果原字符串是非GB3212编码的,如繁体、utf8。
等,系统显示就会出现乱码!主要是中文乱码!
实际上问题在于各编码的转换!

第二、open方法后input读取也存在分字串和字节读取二类。字串读取我没试过。
但字节读取就会出现问题。
如果字节读取出现乱码,可用strconv转换,转成unicode还原!
如果是繁体编码:则用strconv这样转:繁体——unicode——GB3212
相反也成!(有人做过这样的函数,但我没测试)

按这样的原理:UTF8——unicode——GB3212
转换也应可以,但我却不知道如何转!这就是我的问题
大家知道的话给指点一下!



tubo_true 2007-01-17
  • 打赏
  • 举报
回复
我想在编程环境里,显示f8e1这个unicode码位所代表的字,是显示字,想把这个字入库
数据库有的支持,有的不支持,也很邪门。

****************************************************
VB有没有这样一个功能?????
比如
msgbox "\uf8e1" 这个语句是假设的
功能是显示f8e1这个字,而不是“f8e1”
****************************************************

这条语句是我瞎写的,我是想说,VB有没有这种功能,在.net 中,“\u”+码位,是显示文字,而不是显示“码位”字符串,VB有这种类似的功能吗?
tubo_true 2007-01-17
  • 打赏
  • 举报
回复
试完

不能结帖

我上面提过,open 文件名... as #1 ,这种读二进制方法,读出来的码位是正确的
但是,把它赋给变量后,他显示的文字,有正确的,有不正确的,
尤其是F8e1这个unicode码位或其附近的,老是显示问号

你上面的这段代码,我总结为

copyfile 源文件,目标文件

有其他方法吗?
以前有这方面的提问吗?
am i number one ??
tubo_true 2007-01-17
  • 打赏
  • 举报
回复
试试先
ZOU_SEAFARER 2007-01-16
  • 打赏
  • 举报
回复
我来结帖了!!
'*************************************************************************
'**FunctionName:DecipherFile
'**Input :strEncryptFilePath(String) -File Path which has been Encrypted
'** :strDecipherFilePath(String) -File Path which will Save Decipher Code
'**OutPut :bytNewData() -Decipher Code
'**Description :Decipher File which was Encrypted and made a new DecipherFile
'**Global Var :bytNewData
'**Author :YongJun-Zou
'**Data :2007-01-15 14:52:56
'**Version :V1.0.0
'*************************************************************************
Public Sub DecipherFile(strEncryptFilePath As String, strDecipherFilePath As String)
On Error GoTo ToExit '打开错误陷阱
'------------------------------------------------
Dim bytData() As Byte 'Save File Data
Dim lngLoop As Long 'For Loop
Open strEncryptFilePath For Binary As #1
ReDim Preserve bytData(LOF(1) - 1) As Byte
Get #1, 1, bytData 'Get Data from File
Close #1
For lngLoop = 0 To UBound(bytData)
Select Case bytData(lngLoop)
Case 11, 14
bytData(lngLoop) = bytData(lngLoop) - 2
Case 10, 13 'vbCrLf
bytData(lngLoop) = bytData(lngLoop)
Case 0
bytData(lngLoop) = 255
Case Else 'Normal
bytData(lngLoop) = bytData(lngLoop) - 1
End Select
Next
ReDim bytNewData(UBound(bytData)) As Byte
Call CopyMemory(bytNewData(0), bytData(0), UBound(bytData) + 1)

'Save a File that is Decipher Code
' If Dir(strDecipherFilePath) <> "" Then Kill strDecipherFilePath
' Open strDecipherFilePath For Binary As #1
' Put #1, 1, bytData 'Write New File which has been Deciphering
' Close #1

'------------------------------------------------
Exit Sub
'----------------
ToExit:
Debug.Print "Error Data:" & Format(Now, "YYYY-MM-DD HH:MM:SS")
Debug.Print "Error Type:" & Err.Number
Debug.Print "ErrorDescription:" & Err.Description
Debug.Print "ErrorSource:" & "DecipherFile"
Debug.Print "SystemTitle:" & "Form1"
End Sub
加载更多回复(16)
au3反编译源 myAut2Exe - The Open Source AutoIT Script Decompiler 2.9 ======================================================== *New* full support for AutoIT v3.2.6++ :) ... mmh here's what I merely missed in the 'public sources 3.1.0' This program is for studying the 'Compiled' AutoIt3 format. AutoHotKey was developed from AutoIT and so scripts are nearly the same. Drag the compiled *.exe or *.a3x into the AutoIT Script Decompiler textbox. To copy text or to enlarge the log window double click on it. Supported Obfuscators: 'Jos van der Zande AutoIt3 Source Obfuscator v1.0.14 [June 16, 2007]' , 'Jos van der Zande AutoIt3 Source Obfuscator v1.0.15 [July 1, 2007]' , 'Jos van der Zande AutoIt3 Source Obfuscator v1.0.20 [Sept 8, 2007]' , 'Jos van der Zande AutoIt3 Source Obfuscator v1.0.22 [Oct 18, 2007]' , 'Jos van der Zande AutoIt3 Source Obfuscator v1.0.24 [Feb 15, 2008]' , 'EncodeIt 2.0' and 'Chr() string encode' Tested with: AutoIT : v3. 3. 0.0 and AutoIT : v2.64. 0.0 and AutoHotKey: v1.0.48.5 The options: =========== 'Force Old Script Type' Grey means auto detect and is the best in most cases. However if auto detection fails or is fooled through modification try to enable/disable this setting 'Don't delete temp files (compressed script)' this will keep *.pak files you may try to unpack manually with'LZSS.exe' as well as *.tok DeTokeniser files, tidy backups and *.tbl (<-Used in van Zande obfucation). If enable it will keep AHK-Scripts as they are and doesn't remove the linebreaks at the beginning Default:OFF 'Verbose LogOutput' When checked you get verbose information when decompiling(DeTokenise) new 3.2.6+ compiled Exe Default:OFF 'Restore Includes' will separated/restore includes. requires ';

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧