gpt4 book ai didi

file - 打开输入 VB 时指定编码

转载 作者:行者123 更新时间:2023-12-05 00:34:13 25 4
gpt4 key购买 nike

我正在尝试使用以下行打开一个文件以在 Excel 中输入:

Open tmpNmFichier For Input Shared As #iFnum

问题是我的文件有一些字符,如:“é”、“à”……当我用以下内容解析文件时:
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

我的字符“é”...被转换为:“è”或“Ã...”

你知道我如何明确我的文件的编码或类似的东西吗?

最佳答案

使用 FileSystemObject相反

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


TristateUseDefault -2 Opens the file using the system default. 
TristateTrue -1 Opens the file as Unicode.
TristateFalse 0 Opens the file as ASCII.

关于file - 打开输入 VB 时指定编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10996922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com