记录我的工作vb.net应用。在这我有多个文本文件,并需要在文件分割基于一些标识符(重复的字)的记录。 能否请你帮我,因为我是新来vb.net,不知道如何做到这一点。 到目前为止,我已经编码拆分文本文件
If (Directory.Exists(filePath)) Then
'search file in the input path by their search pattern
For Each File As String In Directory.GetFiles(filePath, "*.txt", SearchOption.TopDirectoryOnly)
Console.WriteLine("Reading the current file " + Path.GetFileName(File))
Using sr As StreamReader = New StreamReader(File)
Dim Currentline As String
Dim Identifier As String
Dim statementDate As String
Dim currenttext As String
'getting the unique identifier from the files and removing the white spaces
Identifier = sr.ReadLine.Substring(69, 8)
'checks until the EOF
While Not sr.EndOfStream
currenttext = sr.ReadLine()
'loop through until identified not repeated
Do Until currenttext.Contains(Identifier)
Currentline = sr.ReadLine()
Console.WriteLine(Currentline)
Loop
Console.WriteLine("=========================== Records Ends")
End While
End Using
而且,这是一个需要分割文本文件的截屏。 Text file snap shot
在此先感谢。
我dont't要使用ReadAllLines改变
Identifier = Mid(sr.ReadLine, 1, 5)
。怎么一回事,因为它加载在内存中的文件和可能是内存问题。这可能与StreamReader的 –@VirenderThakur我修订我的答案。 – MrGadget