Reputation: 87
im trying to copy the lines until an empty line is detected but this code lags my computer i dont know what im doing wrong it is because im running while loop inside another while loop? here is my code:
ElseIf String.Compare(line, "the") = 1 And Not line.ToLower().Contains("by") Then
While True
Dim title = New Regex("^\s*$").Matches(line).Count
If title = 1 Then Exit While
builder.AppendLine(line)
builder.AppendLine(reader.ReadLine())
End While
Upvotes: 2
Views: 269
Reputation: 43743
It's hard to tell exactly what you are trying to do, with that short snippet of code, but the reason why it doesn't work is clear. You will get stuck in an infinite loop if title
does not equal 1
. You assume, I think, that the value of line
will change reach time you call reader.ReadLine
inside the While
loop. You probably meant to do something like this:
line = reader.ReadLine()
builder.AppendLine(line)
Upvotes: 2
Reputation: 55467
You're not resetting the line
variable. Something like this should work probably:
While True
Dim title = New Regex("^\s*$").Matches(line).Count
If title = 1 Then Exit While
builder.AppendLine(line)
line = reader.ReadLine()
End While
EDIT
Instead of regex you could instead just use String.IsNullOrWhiteSpace()
which might make your code easier to read in the future.
Upvotes: 3