我有一个程序,可以从文本文件(从 Notes 中使用 UTF 保存)读取文本行(大约 3000-4000 行)。每行由大约 300-900 个字符组成。我使用了这个功能:
Function loadVerbs2(fullPathName As String) As String()
Dim strings(0 To 5000) As String
Dim my_file As Integer
Dim text_line As String
Dim stringNr As Integer
my_file = FreeFile()
Open fullPathName For Input As my_file
stringNr = 0
While Not EOF(my_file)
Line Input #my_file, text_line
'Cut preceding "
While ((Asc(Left$(text_line, 1)) < Asc("a")) Or (Asc(Left$(text_line, 1)) > Asc("z")))
text_line = Mid$(text_line, 2)
Wend
' Cut ending " and ,
While ((Right$(text_line, 1) = Chr$(34)) Or (Right$(text_line, 1) = ","))
text_line = Left$(text_line, Len(text_line) - 1)
Wend
strings(stringNr) = latinCharacter(text_line)
stringNr = stringNr + 1
Wend
Close #my_file
loadVerbs2 = strings
End Function
由于某种原因,该函数不会读取整行,而是剪切它们。
所以我把它改成这样:
Function loadVerbs(fullPathName As String) As String()
Dim strings(0 To 5000) As String
Dim text_line As String
Dim stringNr As Integer
Dim fso As New FileSystemObject
Dim ts As TextStream
Set ts = fso.OpenTextFile(fullPathName)
Do While Not ts.AtEndOfStream
text_line = ts.ReadLine
'Cut preceding "
While ((Asc(Left$(text_line, 1)) < Asc("a")) Or (Asc(Left$(text_line, 1)) > Asc("z")))
text_line = Mid$(text_line, 2)
Wend
' Cut ending " and ,
While ((Right$(text_line, 1) = Chr$(34)) Or (Right$(text_line, 1) = ","))
text_line = Left$(text_line, Len(text_line) - 1)
Wend
strings(stringNr) = latinCharacter(text_line)
stringNr = stringNr + 1
Loop
ts.Close
loadVerbs = strings
End Function
但结果相同。文本中有一些这样的字符:á í é ó à ò ì è â û î ñ ç 这使得这个“latinCharacter”函数需要转换它们,以便我可以将它们放在电子表格中。但这些字符不会阻止 ReadLine 或 Line Input 读取整行。
有什么建议么??