{"title":"VB.NET 从SUM文件读取数据并存入二维数组 - 代码示例","description":"本代码示例演示如何使用VB.NET读取SUM文件中的数据,并将每行7个数据存入二维数组。代码使用StreamReader类读取文件内容,并使用Split方法将每行数据分割为字符串,然后将非空格字符串转换为整数存入二维数组。","keywords":"VB.NET, SUM文件, 读取数据, 二维数组, 代码示例, StreamReader, Split, Integer.Parse","content":""Dim filePath As String = "C:\path\to\file.sum" ' SUM文件路径\nDim data As New List(Of List(Of Integer))() ' 二维数组\n\nUsing reader As New StreamReader(filePath)\n Dim lineCount As Integer = 0 ' 行计数器\n Dim line As String = reader.ReadLine() ' 读取第一行数据\n\n While line IsNot Nothing\n lineCount += 1\n\n If lineCount >= 4 AndAlso line.Trim() <> "0" Then ' 从第4行开始,并且最后一行不为0时继续读取数据\n Dim rowData As New List(Of Integer)() ' 存放一行数据的列表\n Dim lineData As String() = line.Split(" "c) ' 将行数据分割为字符串数组\n\n ' 将非空格字符串转换为整数,并添加到行数据列表中\n For Each str As String In lineData\n If str.Trim() <> "" Then\n rowData.Add(Integer.Parse(str))\n End If\n Next\n\n data.Add(rowData) ' 添加一行数据到二维数组中\n End If\n\n line = reader.ReadLine() ' 读取下一行数据\n End While\nEnd Using\n\n' 输出二维数组中的数据\nFor Each row As List(Of Integer) In data\n For Each value As Integer In row\n Console.Write(value & " ")\n Next\n\n Console.WriteLine()\nNext\n"}


原文地址: https://www.cveoy.top/t/topic/pQSY 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录