From a button click I am trying to read a text file and then output just the last 2 lines into a Label. The data in the text file changes regular but the format is always the same.
This is an example of what is in the text file.
1393
00:23:12,000 --> 00:23:13,000
2020/08/12 12:43:47
+DMR DCC=4
Slot 1 TG=9003 RID=69
The last 2 lines is what I am interested in getting which in the above example would be
+DMR DCC=4
Slot 1 TG=9003 RID=69
This is what I have so far which seems to work but I just feel its a bit messy and was wondering if anyone had any other suggestions.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label1.text= ReadLog()
End Sub
Public Function ReadLog() As String
Dim lines() As String = IO.File.ReadAllLines("C:\MyApp\log.txt")
If lines.Length <= 4 Then Return String.Join(Environment.NewLine, lines)
Dim lines4(3) As String
Array.Copy(lines, lines.Length - 3, lines4, 0, 3)
Return String.Join(Environment.NewLine, lines4)
End Function