当打开输入VB时指定编码 [英] Specify encoding when Open for input VB
本文介绍了当打开输入VB时指定编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
打开tmpNmFichier输入共享为# iFnum
问题是我的文件有一些字符,如:é,à..当我解析文件时:
Dim s As String
行输入#iFnum ,s
如果Len(s)> 0然后
v = Split(s,tmpSeparateur)
Else
ReDim v(-1到-1)
结束如果
我的字符é...被转换为:Ã或Ã
$ b $你有什么想法可以明确我的文件的编码或类似的东西吗?
解决方案
使用 FileSystemObject
公共函数GetContent(fpath $)As String
'参考:
'Microsoft Scripting Runtime // Scripting.FileSystemObject
Dim fso As New Scripting.FileSystemObject,content $
如果fso.FileExists(fpath)Then
content = fso.OpenTextFile(fpath,ForReading,False,TristateTrue).ReadAll()
GetContent = content
Else
MsgBox无效的文件路径。
GetContent = vbNullChar
如果
结束函数
值
TristateUseDefault -2使用系统默认值打开文件。
TristateTrue -1以Unicode格式打开文件。
TristateFalse 0以ASCII格式打开文件。
I'm trying to open a file for input in Excel with this line :
Open tmpNmFichier For Input Shared As #iFnum
The problem is that my file has some characters like : "é", "à" ... When I'm parsing the file with :
Dim s As String
Line Input #iFnum, s
If Len(s) > 0 Then
v = Split(s, tmpSeparateur)
Else
ReDim v(-1 To -1)
End If
my characters "é" ... are transformed in : "è" or "Ã..."
Do you have any idea how i can explicit the encoding of my file or something like that?
解决方案
Use FileSystemObject
instead
Public Function GetContent(fpath$) As String
'REFERENCES:
'Microsoft Scripting Runtime // Scripting.FileSystemObject
Dim fso As New Scripting.FileSystemObject, content$
If fso.FileExists(fpath) Then
content = fso.OpenTextFile(fpath, ForReading, False, TristateTrue).ReadAll()
GetContent = content
Else
MsgBox "Invalid file path."
GetContent = vbNullChar
End If
End Function
values
TristateUseDefault -2 Opens the file using the system default.
TristateTrue -1 Opens the file as Unicode.
TristateFalse 0 Opens the file as ASCII.
这篇关于当打开输入VB时指定编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文