I'm creating a software which is supposed to read a text file and display only certain lines in which a certain string occurs. I will attach the file I am using:
[fltsim.0]
title=Boeing 737-800 Paint1
sim=Boeing737-800
model=
panel=
sound=
texture=1
kb_checklists=Boeing737-800_check
kb_reference=Boeing737-800_ref
atc_id=N737W
atc_airline=Boeing
atc_flight_number=
ui_manufacturer="Boeing"
ui_type="737-800"
ui_variation="Boeing livery"
ui_typerole="Commercial Airliner"
ui_createdby="Microsoft Corporation"
description="One should hardly be surprised that the world's most prolific manufacturer of commercial aircraft is also the producer of the world's most popular jetliner. The 737 became the best-selling commercial jetliner worldwide when orders for it hit 1,831 in June 1987 (surpassing Boeing's own 727 as the previous champ). However, it wasn't always that way\s in the first few years of production, there were so few orders that Boeing considered canceling the program. They didn't, and the airplane has more than proven itself in over three decades of service."
[fltsim.1]
title=Boeing 737-800 Paint2
sim=Boeing737-800
model=
panel=
sound=
texture=2
kb_checklists=Boeing737-800_check
kb_reference=Boeing737-800_ref
atc_id=N737X
atc_airline=World Travel
atc_flight_number=
ui_manufacturer="Boeing"
ui_type="737-800"
ui_variation="World Travel Airlines"
ui_typerole="Commercial Airliner"
ui_createdby="Microsoft Corporation"
description="One should hardly be surprised that the world's most prolific manufacturer of commercial aircraft is also the producer of the world's most popular jetliner. The 737 became the best-selling commercial jetliner worldwide when orders for it hit 1,831 in June 1987 (surpassing Boeing's own 727 as the previous champ). However, it wasn't always that way\s in the first few years of production, there were so few orders that Boeing considered canceling the program. They didn't, and the airplane has more than proven itself in over three decades of service."
As you can see, the header, [fltsim.0,1,etc.] increments by one every time, and underneath each header is a host of information that I need to pull out. I wish to pull out title={string}
. I was able to pull out the first occurrence of title, however I cannot seem to figure out how to pull out the rest. All in all, my objective is to read specific data from that file (with more than one occurance) and also write to the file the same way.
Example: If I wanted to pull out title={string}
, I would want to get Boeing 737-800 Paint 1, and Boeing 737-800 Paint 2 (they could be named anything).
Here is the code I was working with (only found first occurrence):
Dim path As String = "C:\Aircraft.cfg" '<<<<<CHANGE THIS LATER
'GET LINE HUMBER OF STRING
Dim firstNumber As Integer
Dim toSearch = "ui_variation="
Dim lineNumber = File.ReadLines(path).
Where(Function(l) l.Contains(toSearch))
Select(Function(l, index) index)
If lineNumber.Any Then
firstNumber = lineNumber.First
End If
'READS WHAT IS IN THE LINE WITH LINE NUMBER
Using file As New StreamReader(path)
For i As Integer = 1 To firstNumber + 1
If file.ReadLine() Is Nothing Then
Throw New ArgumentOutOfRangeException("lineNumber")
End If
Next
Dim line As String = file.ReadLine()
If line Is Nothing Then
Throw New ArgumentOutOfRangeException("lineNumber")
End If
MsgBox(line)
End Using