【发布时间】:2016-09-30 13:50:18
【问题描述】:
我有一个问题,我需要逐行阅读文本文件,如果满足某些条件,则将每一行放入一个字符串或另一个字符串中。我遇到的问题是这需要很长时间,我只是想知道是否有更快的做事方式。我已经做了很多关于如何做到这一点的研究,这是我能想到的最好的。谢谢。 (每次都附加两个字符串,因为必须在之后立即将两个字符串输出到文本文件)。
内容在一个巨大的文本文件中,其中一条信息以“aaa”开头的一行开始。我必须通过查找行何时以“aaa”开头来查看分隔这些信息的文本文件。将一条信息与 fullStr1 或 fullStr2 分开的标准是索引 29 处的字符是空格(“ “) 或不。谢谢。
Using reader As StreamReader = New StreamReader(file)
Dim line As String = reader.ReadLine
Do While (Not line Is Nothing)
If line.Substring(0, 3) = "aaa" AndAlso line.Substring(29, 1) <> " " Then
Do
fullStr1 = fullStr1 & line & vbCrLf
line = reader.ReadLine
Loop While (Not line Is Nothing AndAlso line.Substring(0, 3) <> "aaa")
ElseIf line.Substring(0, 3) = "aaa" AndAlso line.Substring(29, 1) = " " Then
Do
fullStr2 = fullStr2 & line & vbCrLf
line = reader.ReadLine
Loop While (Not line Is Nothing AndAlso line.Substring(0, 3) <> "aaa")
End If
Loop
End Using
【问题讨论】:
标签: .net vb.net visual-studio streamreader