以下代码用于逐行读取文件.
它只是一个非常早期的版本,所以我想做的就是在即时窗口中显示字符串.它工作正常,除了诸如ÄÖÖèà等字符被带有问号的黑色方块所取代.根据文档,文件阅读器应该与UTF-8字符兼容,所以我不知道有什么问题.
... Dim reader = File.OpenText(filetoimport.Text) Dim line As String = Nothing Dim lines As Integer = 0 While (reader.Peek() <> -1) line = reader.ReadLine() If line.StartsWith("<item key=""") Then Dim Firstpart As String = Nothing Firstpart = line.Substring(11,line.IndexOf(""" value=") - 11) Debug.WriteLine(Firstpart) lines = lines + 1 Label3.Text = lines Application.DoEvents() Else Label3.Text = lines Application.DoEvents() End If End While ...
该文件是ANSI编码的,不是UTF-8,但读者使用UTF-8.
像这样……我用它来读汉字……
Dim reader as StreamReader = My.Computer.FileSystem.OpenTextFileReader(filetoimport.Text) Dim a as String Do a = reader.ReadLine ' ' Code here ' Loop Until a Is Nothing reader.Close()