記錄我的工作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