单词拆分失败,超过 3 个单词
Word split fails with more then 3 words
我尝试每隔 +
拆分一个字符串,然后每隔 |
,当我尝试从拆分 words1(0-3)
中只读取 3 个单词时它工作正常,但是当我尝试读取 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"
<b>Dim status As String = words1(4)</b>
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(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
但正如我上面所说,一旦使用 words1(4),它就会使整个函数崩溃...
它会捕获并失败并给出错误消息,但是当我尝试为异常错误执行 msgbox(ex)
时,没有 msgbox
弹出并且程序继续。
如果有人能解决这个问题或给我一些帮助,我将不胜感激,提前致谢,如果这也让我感到困惑,我深表歉意!
您的拆分功能工作正常,但以下几行有错误(有 2 行):
RichTextBox1.AppendText("+" & words1(0) & "|" & words1(1) & "|" & words1(2) & "|" & words1(3) & "|" & words(4))
最后一个 words(4)
应该是 words1(4)
.
你的程序中有两个循环:
循环1:
words1(0)>>事物 v2.exe
单词 1(1)>>1.0.0.1
单词 1(2)>>http://example.com/uploads/Thing v2.exe
字数 1(3)>>205824
words1(4)>>小学
循环2:
words1(0)>>事物 v2 DLL.dll
单词 1(1)>>1.0.0.1
单词 1(2)>>http://example.com/uploads/Thing DLL.dll
字数 1(3)>>1097728
单词 1(4)>>中学
您似乎将下一行中的单词 1(4) 拼错为单词 (4)
RichTextBox1.AppendText("+" & words1(0) & "|" & words1(1) & "|" & words1(2) & "|" & words1(3) & "|" & words(4))
我尝试每隔 +
拆分一个字符串,然后每隔 |
,当我尝试从拆分 words1(0-3)
中只读取 3 个单词时它工作正常,但是当我尝试读取 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"
<b>Dim status As String = words1(4)</b>
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(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
但正如我上面所说,一旦使用 words1(4),它就会使整个函数崩溃...
它会捕获并失败并给出错误消息,但是当我尝试为异常错误执行 msgbox(ex)
时,没有 msgbox
弹出并且程序继续。
如果有人能解决这个问题或给我一些帮助,我将不胜感激,提前致谢,如果这也让我感到困惑,我深表歉意!
您的拆分功能工作正常,但以下几行有错误(有 2 行):
RichTextBox1.AppendText("+" & words1(0) & "|" & words1(1) & "|" & words1(2) & "|" & words1(3) & "|" & words(4))
最后一个 words(4)
应该是 words1(4)
.
你的程序中有两个循环: 循环1: words1(0)>>事物 v2.exe
单词 1(1)>>1.0.0.1
单词 1(2)>>http://example.com/uploads/Thing v2.exe
字数 1(3)>>205824
words1(4)>>小学
循环2: words1(0)>>事物 v2 DLL.dll
单词 1(1)>>1.0.0.1
单词 1(2)>>http://example.com/uploads/Thing DLL.dll
字数 1(3)>>1097728
单词 1(4)>>中学
您似乎将下一行中的单词 1(4) 拼错为单词 (4)
RichTextBox1.AppendText("+" & words1(0) & "|" & words1(1) & "|" & words1(2) & "|" & words1(3) & "|" & words(4))