Vb.net streamReader将文本文件读取为无限
我在VB.net上工作,我是一个使用流阅读器的文本文件阅读器。但问题是streamReader不知道它在EOF上。 这是我的密码Vb.net streamReader将文本文件读取为无限,vb.net,console,Vb.net,Console,我在VB.net上工作,我是一个使用流阅读器的文本文件阅读器。但问题是streamReader不知道它在EOF上。 这是我的密码 Do Until SR.EndOfStream Currentline = SR.ReadLine() Do While Identifier <> Currentline recordsCount = recordsCount + 1 'if it is second ro
Do Until SR.EndOfStream
Currentline = SR.ReadLine()
Do While Identifier <> Currentline
recordsCount = recordsCount + 1
'if it is second row
If recordsCount = 1 Then
fields.Add("StatementDate", Currentline.Trim())
Currentline = SR.ReadLine()
Continue Do
End If
'if there is first row
If recordsCount = 2 Then
Console.WriteLine("Current record " & recordsCount)
Dim secondRow As New List(Of String)
secondRow.AddRange(Currentline.Trim().Split(New Char() {" ", "\t"}, StringSplitOptions.RemoveEmptyEntries))
'account number
AcctNum = secondRow.First()
fields.Add("AccountNumber", AcctNum)
fields.Add("PaymentDueDate", secondRow.ElementAt(2))
fields.Add("PastDueAmt", secondRow.ElementAt(3))
fields.Add("CurrentAmtDue", secondRow.ElementAt(4))
fields.Add("MinPaymentDue", secondRow.ElementAt(5))
fields.Add("NewBalance", secondRow.ElementAt(6))
'moving to next record
Currentline = SR.ReadLine()
End If
'if the mailing addres row
If recordsCount = 3 Then
Dim nextmatch As String
addresCounter = addresCounter + 1
Console.WriteLine("\n")
Console.WriteLine("address counter is " & addresCounter)
accountIdentifier = AcctNum
nextmatch = Currentline
' while account number is not repeated
Do While nextmatch <> accountIdentifier
'loop until end line of mailing address found
If (Currentline.Contains("HOME")) Then
'adding the last line of address
mailingAddressList.Add(Currentline.Substring(0, 53).Trim())
'adding the statement header to the list
statementWindowList.AddRange(Currentline.Substring(53, 26).Split(" "))
fields.Add("HOME", statementWindowList.ElementAt(0))
fields.Add("EQUITY", statementWindowList.ElementAt(1))
fields.Add("LINE", statementWindowList.ElementAt(2))
fields.Add("OF", statementWindowList.ElementAt(3))
fields.Add("CREDIT", statementWindowList.ElementAt(4))
Currentline = SR.ReadLine()
'if more address is pending than add it to the same list
If Not Currentline.Contains(accountIdentifier) Then
mailingAddressList.Add(Currentline.Trim())
Currentline = SR.ReadLine()
End If
statementReturnedDetails.AddRange(Currentline.Trim().Split(New Char() {" ", "\t"}, StringSplitOptions.RemoveEmptyEntries))
If statementReturnedDetails.Any() Then
fields.Add("CredtiLimit", statementReturnedDetails.ElementAt(3))
fields.Add("AvailableCredit", statementReturnedDetails.ElementAt(4))
fields.Add("Previous_Balance", statementReturnedDetails.ElementAt(6))
nextmatch = statementReturnedDetails.ElementAt(0)
End If
Continue Do
End If
'adding the mailing address
mailingAddressList.Add(Currentline.Trim())
'moving to the next row
Currentline = SR.ReadLine()
nextmatch = Currentline
Loop
addresCounter = 0
Currentline = SR.ReadLine()
End If
'for body of the statement
If recordsCount > 3 Then
statementbody.Add(Currentline)
Currentline = SR.ReadLine()
End If
Loop
Loop
Do直到SR.EndOfStream
Currentline=SR.ReadLine()
当标识符处于当前行时执行此操作
RecordScont=RecordScont+1
“如果是第二排
如果recordsCount=1,则
fields.Add(“StatementDate”,Currentline.Trim())
Currentline=SR.ReadLine()
继续做
如果结束
“如果有第一排
如果recordsCount=2,则
Console.WriteLine(“当前记录”和recordsCount)
将第二行调整为新列表(字符串)
secondRow.AddRange(Currentline.Trim().Split(新字符(){“”“\t”},StringSplitOptions.RemoveEmptyEntries))
“账号
AcctNum=secondRow.First()
字段。添加(“AccountNumber”,AcctNum)
字段。添加(“PaymentDueDate”,第二行。元素地址(2))
fields.Add(“PastDueAmt”,secondRow.ElementAt(3))
fields.Add(“CurrentAmtDue”,secondRow.ElementAt(4))
字段。添加(“MinPaymentDue”,第二行。元素地址(5))
字段。添加(“NewBalance”,第二行。元素地址(6))
“转到下一个记录
Currentline=SR.ReadLine()
如果结束
'如果邮件地址为行
如果recordsCount=3,则
Dim nextmatch作为字符串
addresCounter=addresCounter+1
Console.WriteLine(“\n”)
Console.WriteLine(“地址计数器为”&addresCounter)
accountIdentifier=AcctNum
下一个匹配=当前线路
'而帐号不重复
Do While nextmatch accountIdentifier
'循环,直到找到邮寄地址的结束行
如果(Currentline.Contains(“HOME”)),则
'添加地址的最后一行
mailingAddressList.Add(Currentline.Substring(0,53).Trim())
'将语句标题添加到列表中
语句WindowList.AddRange(Currentline.Substring(53,26).Split(“”)
fields.Add(“HOME”,statementWindowList.ElementAt(0))
fields.Add(“EQUITY”,statementWindowList.ElementAt(1))
字段。添加(“行”,语句WindowList.ElementAt(2))
fields.Add(“OF”,statementWindowList.ElementAt(3))
字段。添加(“贷方”,语句WindowList.ElementAt(4))
Currentline=SR.ReadLine()
'如果挂起的地址多于,请将其添加到同一列表中
如果不是Currentline.Contains(accountIdentifier),则
mailingAddressList.Add(Currentline.Trim())
Currentline=SR.ReadLine()
如果结束
语句ReturnedDetails.AddRange(Currentline.Trim().Split(新字符(){“”“\t”},StringSplitOptions.RemoveEmptyEntries))
如果statementReturnedDetails.Any()则
fields.Add(“CredtiLimit”,statementReturnedDetails.ElementAt(3))
fields.Add(“AvailableCredit”,statementReturnedDetails.ElementAt(4))
字段。添加(“上一次余额”,语句返回详细信息。元素位于(6))
nextmatch=statementReturnedDetails.ElementAt(0)
如果结束
继续做
如果结束
'添加邮寄地址
mailingAddressList.Add(Currentline.Trim())
“移到下一排
Currentline=SR.ReadLine()
下一个匹配=当前线路
环
addresCounter=0
Currentline=SR.ReadLine()
如果结束
声明的主体部分
如果recordsCount>3,则
statementbody.Add(Currentline)
Currentline=SR.ReadLine()
如果结束
环
环
我只想告诉流reade它的EOF,然后就出来了。但它仍然毫无意义 每次读取行之后,您应该检查EndOfStream,或者如果返回的字符串为Nothing,则不应该有两个
Do
循环。应该有一个循环来测试这两个条件。我使用了两个循环,因为第一个循环将检查EOF并且发送将基于某些条件获得记录。考虑一个更简单的循环,将所有行读取到一个字符串列表中,然后对该集合进行其余的处理。