【问题标题】:Read textfile, specific line. VB.net读取文本文件,特定行。 VB.net
【发布时间】:2016-10-19 01:46:21
【问题描述】:

我有一个这样的文本文件:

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

我想从我的 vb.net 程序中读取文本文件,例如,在它显示 EntityList = 0x04A4BA64 的第一行,我想从中获取 0x04A4BA64 并将其保存为整数。

我试图做这样的事情,但这不是我真正想要的,它也不起作用。

  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)

【问题讨论】:

  • 你复制了这个link的代码吗?

标签: vb.net


【解决方案1】:

您需要打开文件并仅选择包含您的模式的行,然后将该行的第二部分转换为给定基数 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-10
    • 2020-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-25
    相关资源
    最近更新 更多