我读了一个文本文件的行,但在空行上中断。
Using sr As New StreamReader(openFileDialog1.OpenFile())
Dim text As [String] = sr.ReadToEnd()
Dim lines As String() = text.Split(vbCrLf)
For Each line As String In lines
Dim cleanline = line.Trim()
Dim words As String() = cleanline.Split(" ")
For Each word As String In words
If word.StartsWith("a", True, Nothing) OrElse word.StartsWith("e", True, Nothing) OrElse word.StartsWith("i", True, Nothing) OrElse word.StartsWith("o", True, Nothing) OrElse word.StartsWith("u", True, Nothing) OrElse word.StartsWith("y", True, Nothing) Then
System.Console.Write(word & "ay ")
Else
Dim mutated As String = word.Substring(1, word.Length - 1)
mutated = mutated & word.Substring(0, 1) & "yay "
System.Console.Write(mutated)
End If
Next
System.Console.Write(vbLf)
Next
End Using我正在使用这输入。
我知道这个错误:

我应该更改什么来防止这个运行时错误并继续处理?
发布于 2013-11-19 20:08:32
您应该这样做,以确保您没有这个错误:
...
For Each word As String In words
If (word.Equals("")) Then
Continue For
End If
...这将确保您永远不会尝试转换空字符串。
发布于 2013-11-19 19:42:39
代之以:
System.Console.Write(vbLf)在这方面:
Console.WriteLine()For Each line As String In lines
If line.IsNullOrWhiteSpace() Then Exit Forhttps://stackoverflow.com/questions/20080488
复制相似问题