简体   繁体   中英

Read textfile, specific line. VB.net

I've got a text file like this:

EntityList = 0x04A4BA64
LocalPlayer = 0x00A30504
FlashDuration = 0x0000A2F8
RadarBase = 0x04E807BC
ScoreBoardBase/GameResources = 0x04A6BCBC
ServerBase = 0x04E92A10
EnginePointer = 0x005B6314
SetViewAngles = 0x00004D0C
CrosshairIndex = 0x0000AA44
GlowObjectBase = 0x00000000
ViewMatrix1 = 0x04A3D604
ViewMatrix2 = 0x04A3D714

And I'd like to read the textfile from my vb.net program and, for example, on the first line where it says EntityList = 0x04A4BA64, I would love to get the 0x04A4BA64 from it and save it as a Integer.

I tried to do something like this, but this isn't what I really want and it's not working either.

  Public Sub Test()
        Dim reader As New System.IO.StreamReader("C:\test.txt")
        Dim allLines As List(Of String) = New List(Of String)
        Do While Not reader.EndOfStream
            allLines.Add(reader.ReadLine())
        Loop
        reader.Close()
    End Sub

    Public oEntityList As Integer = ReadLine(1, allLines)

You need to open the file and select only the lines that contains your pattern then convert the second part of the line to an integer given a base 16

Dim values = new List(Of Integer)()
For Each line in File.ReadLines("C:\test.txt") _
                     .Where(Function(x) x.Trim().StartsWith("EntityList"))

    Dim parts = line.Split("="c)
    if parts.Length > 1 Then
       values.Add(Convert.ToInt32(parts(1).Trim(), 16)
    End If
Next

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM