我尝试每隔+
然后每|
分割一个字符串,当我尝试从分割words1(0-3)
中只读取3个单词时它会正常工作,但是当我尝试阅读时{ {1}}整个函数失败了......这是代码:
words1(4)
以上内容完全没有问题,但是当你像这样添加Private Function SetUpdateData()
Try
Dim delimiterChars As Char() = {"+"c}
Dim words As String() = updatelist.Split(delimiterChars)
Dim i As Integer = 1
Do While (i < words.Length)
Dim delimiterChars1 As Char() = {"|"c}
Dim words1 As String() = words(i).Split(delimiterChars1)
Dim name As String = words1(0)
Dim version As String = words1(1)
Dim fileurl As String = words1(2)
Dim size As String = (words1(3) / 1024D / 1024D).ToString("0.00") & " MB"
Dim cversion As FileVersionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(Directory.GetCurrentDirectory() & "\" & name))
If My.Computer.FileSystem.FileExists(Directory.GetCurrentDirectory() & "\" & name) Then
If Not version.Contains(cversion.FileVersion) Then
DataGridView1.Rows.Add(name, version, size)
RichTextBox1.AppendText("+" & words1(0) & "|" & words1(1) & "|" & words1(2) & "|" & words1(3))
End If
Else
DataGridView1.Rows.Add(name, version, size)
RichTextBox1.AppendText("+" & words1(0) & "|" & words1(1) & "|" & words1(2) & "|" & words1(3))
End If
i = (i + 1)
Loop
Catch ex As Exception
MsgBox("error")
End Try
End Function
时:
words1(4)
它正在拆分的字符串是:
Private Function SetUpdateData()
Try
Dim delimiterChars As Char() = {"+"c}
Dim words As String() = updatelist.Split(delimiterChars)
Dim i As Integer = 1
Do While (i < words.Length)
Dim delimiterChars1 As Char() = {"|"c}
Dim words1 As String() = words(i).Split(delimiterChars1)
Dim name As String = words1(0)
Dim version As String = words1(1)
Dim fileurl As String = words1(2)
Dim size As String = (words1(3) / 1024D / 1024D).ToString("0.00") & " MB"
Dim status As String = words1(4)
Dim cversion As FileVersionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(Directory.GetCurrentDirectory() & "\" & name))
If My.Computer.FileSystem.FileExists(Directory.GetCurrentDirectory() & "\" & name) Then
If Not version.Contains(cversion.FileVersion) Then
DataGridView1.Rows.Add(name, version, size)
RichTextBox1.AppendText("+" & words1(0) & "|" & words1(1) & "|" & words1(2) & "|" & words1(3) & "|" & words(4))
End If
Else
DataGridView1.Rows.Add(name, version, size)
RichTextBox1.AppendText("+" & words1(0) & "|" & words1(1) & "|" & words1(2) & "|" & words1(3) & "|" & words(4))
End If
i = (i + 1)
Loop
Catch ex As Exception
MsgBox("error")
End Try
End Function
所有应输出的内容:
+Thing v2.exe|1.0.0.1|http://example.com/uploads/Thing v2.exe|205824|Primary+Thing v2 DLL.dll|1.0.0.1|http://example.com/uploads/Thing DLL.dll|1097728|Secondary
但是如上所述,一旦使用了words1(4),它就会崩溃整个函数......
它会捕获并失败并提供错误消息,但是当我尝试words1(0) - Thing v2.exe
words1(1) - 1.0.0.1
words1(2) - http://example.com/uploads/Thing v2.exe
words1(3) - 205824
words1(4) - Primary
执行异常错误时,不会弹出msgbox(ex)
,程序就会继续。
如果有人可以解决这个问题或者给我一些非常感谢的帮助,请提前感谢,如果这对我来说太困惑也很抱歉!
答案 0 :(得分:0)
您的拆分功能正常,但以下行有错误(其中有两行):
RichTextBox1.AppendText("+" & words1(0) & "|" & words1(1) & "|" & words1(2) & "|" & words1(3) & "|" & words(4))
最后words(4)
应为words1(4)
。
答案 1 :(得分:0)
程序中有两个循环: 循环1: words1(0)&gt;&gt; Thing v2.exe
words1(1)&GT;&GT; 1.0.0.1
words1(2)&gt;&gt; http://example.com/uploads/Thing v2.exe
words1(3)&GT;&GT; 205824
words1(4)&GT;&GT;主
循环2: words1(0)&gt;&gt; Thing v2 DLL.dll
words1(1)&GT;&GT; 1.0.0.1
words1(2)&gt;&gt; http://example.com/uploads/Thing DLL.dll
words1(3)&GT;&GT; 1097728
words1(4)&GT;&GT;次要
看来你拼错了你的单词1(4)到下面一行的单词(4)
RichTextBox1.AppendText("+" & words1(0) & "|" & words1(1) & "|" & words1(2) & "|" & words1(3) & "|" & words(4))