{/'title/':/'VB.NET读取SUM文件数据并存入二维数组,实现任意行、列数据查找 - 代码示例/',/'description/':/'本文介绍使用VB.NET读取SUM文件数据,并将其存入二维数组,实现任意行、列数据的查找功能。示例代码展示了读取文件、数据解析、数组存储以及数据查找的步骤,并提供了可供参考的代码实现。/',/'keywords/':/'VB.NET, SUM文件, 二维数组, 数据读取, 数据查找, 代码示例/',/'content/':/'///'Imports System.IO//n//nModule Module1//n//tSub Main()//n//t/tDim filePath As String = ///'your_file_path///' ' 替换为SUM文件的路径//n//t/tDim data As Integer(,) = ReadSumFile(filePath)//n//n//t/t' 测试查找数据//n//t/tDim row As Integer = 2 ' 查找第2行//n//t/tDim col As Integer = 3 ' 查找第3列//n//t/tDim value As Integer = GetCellValue(data, row, col)//n//t/tConsole.WriteLine(///'第///' & row & ///'行第///' & col & ///'个数据为:///' & value)//n//n//t/tConsole.ReadLine()//n//tEnd Sub//n//n//tFunction ReadSumFile(filePath As String) As Integer(,)//n//t/tDim lines As String() = File.ReadAllLines(filePath)//n//t/tDim data As New List(Of Integer())//n//n//t/tFor i As Integer = 3 To lines.Length - 1 Step 3//n//t/t/tDim lineData As Integer() = Array.ConvertAll(lines(i).Split(///' ///'c), Function(x) Integer.Parse(x))//n//t/t/tdata.Add(lineData)//n//n//t/t/t' 判断最后一行是否全为0,如果是则结束读取//n//t/t/tDim isEnd As Boolean = True//n//t/t/tFor Each value As Integer In lineData//n//t/t/t/tIf value <> 0 Then//n//t/t/t/t/tisEnd = False//n//t/t/t/t/tExit For//n//t/t/t/tEnd If//n//t/t/tNext//n//n//t/t/tIf isEnd Then//n//t/t/t/tExit For//n//t/t/tEnd If//n//t/tNext//n//n//t/t' 转换为二维数组//n//t/tDim result(data.Count - 1, 6) As Integer//n//t/tFor i As Integer = 0 To data.Count - 1//n//t/t/tFor j As Integer = 0 To 6//n//t/t/t/tresult(i, j) = data(i)(j)//n//t/t/tNext//n//t/tNext//n//n//t/tReturn result//n//tEnd Function//n//n//tFunction GetCellValue(data As Integer(,), row As Integer, col As Integer) As Integer//n//t/tReturn data(row - 1, col - 1)//n//tEnd Function//nEnd Module/


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

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