【发布时间】:2012-10-26 00:08:55
【问题描述】:
请看下面的代码:
Try
Dim Reader As New System.IO.StreamReader(PositionsFileName)
Do While Reader.Peek() <> -1
Dim Positions() As String = Reader.ReadLine().Split("|")
If (Positions(0) Is Nothing) Or (Positions(1) Is Nothing) Or (Positions(2) Is Nothing) Then
' something
End If
Loop
Catch ex As Exception
ex.Source = Nothing
End Try
我正在读取一个文件并期待格式化某事|某事1|某事2。我试图将它设置为“Nothing”到不存在的数组索引(文件格式已损坏),以便 If 语句顺利进行,但似乎我做错了。能给我一些提示吗?
【问题讨论】:
-
它会读多少“东西”?您可以执行 If Position.lenght() = 0 来了解拆分是否成功。
-
您应该删除您的
Catch ex As Exception。它并不能真正帮助您编写更好的代码,而只是隐藏错误。