我正在尝试解析文本文件的每一行,但它一直给我一个错误“System.IndexOutOfRangeException”。
“servers.lst”中的每一行都按以下顺序排列:
服务器名称|服务器主机|服务器端口|服务器 URL|客户端类型|客户端版本|客户端 URL
每行代表一个服务器。但我无法正确解析它。它要么返回完整文件、空白变量或错误。
这是我的代码:
Dim reader As String = My.Computer.FileSystem.ReadAllText("servers.lst")
Dim s() As String
Dim TotalServers As String = reader.Length
Dim x As Integer = 0
Dim myArray As String() = reader.Split("|"c)
For x = 1 To TotalServers
Servers(x).ServerName = myArray(0)
Servers(x).ServerIP = myArray(1)
Servers(x).ServerPort = myArray(2)
Servers(x).ServerURL = myArray(3)
Servers(x).Client = myArray(4)
Servers(x).ClientVer = myArray(5)
Servers(x).ClientURL = myArray(6)
Form1.ListBox1.Items.Add(Servers(x).ServerName)
x += 1
Next
我正在尝试返回每个服务器的名称,但我遇到了困难。
*编辑:这是我的结构代码:
Structure ServerData
Public ServerName As String
Public ServerPort As Long
Public ServerURL As String
Public ServerIP As String
Public Client As String
Public ClientVer As String
Public ClientURL As String
End Structure
Public Servers As ServerData()
谢谢你。