vb.net读取txt文件数据,并且转换为二维数组
比如:C:\1.txt:array,啊array.啊啊啊,array打开这个文件,转换为数组:array={{"array","啊"},{"array","啊啊"},{"...
比如:
C:\1.txt:
array,啊
array.啊啊
啊,array
打开这个文件,转换为数组:
array = {{"array","啊"},{"array","啊啊"},{"啊","array"}} 展开
C:\1.txt:
array,啊
array.啊啊
啊,array
打开这个文件,转换为数组:
array = {{"array","啊"},{"array","啊啊"},{"啊","array"}} 展开
展开全部
Public Class Func
Public Shared Sub Main() '测试代码!
Dim Temp As String()() = Func.GetArrayByTxt("D:\Test.txt")
End Sub
Public Shared Function GetArrayByTxt(path As String) As String()()
Dim arr As String() = IO.File.ReadAllLines(path, Encoding.Default)
Dim par As Char() = {",", "."}
Dim result(arr.Length - 1)() As String
For i As Integer = 0 To arr.Length - 1
result(i) = arr(i).Split(par)
Next
Return result
End Function
End Class
追问
请问怎么使用呢?
追答
GetArrayByTxt("C:\1.txt") 这个函数输出的就是{{"array","啊"},{"array","啊啊"},{"啊","array"}}这个结果!
也就是Dim array As String()() = GetArrayByTxt("C:\1.txt")
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询