VB.NET 读取 PM 文件:判断格式并提取数据
您可以使用以下代码来实现您的需求:
Dim filePath As String = "C:\path\to\file.pm"
Dim lines As String() = File.ReadAllLines(filePath)
' 判断第一行是否为“HINTCAD5.83_PM_SHUJU_PM”
If lines.Length > 0 AndAlso lines(0) <> "HINTCAD5.83_PM_SHUJU_PM" Then
Console.WriteLine("文件格式不正确。")
Return
End If
Dim dataArray As New List(Of Integer)()
' 从第4行开始读取7个数据
For i As Integer = 3 To lines.Length - 1
Dim line As String = lines(i)
Dim data As Integer
If Integer.TryParse(line, data) Then
dataArray.Add(data)
' 如果1行数据都为0时停止
If dataArray.All(Function(d) d = 0) Then
Exit For
End If
' 只读取7个数据
If dataArray.Count = 7 Then
Exit For
End If
End If
Next
' 输出数组内容
For Each data As Integer In dataArray
Console.WriteLine(data)
Next
请注意,您需要将"C:\path\to\file.pm"替换为您实际的文件路径。此外,如果您需要将数据存储在数组中,您可以将dataArray更改为您想要使用的任何集合类型。
原文地址: https://www.cveoy.top/t/topic/pMB5 著作权归作者所有。请勿转载和采集!