2012-09-26 18 views

回答

1

最好的方法的下一行是为了避免所有手动解析CSV和使用可用的CSV阅读器的一个替代。例如this fast CSV-reader


而不是对例外作出反应,我会跳过空行首先。

取而代之的是StreamReader,你也可以使用File.ReadLines使用LINQ:

Dim lines = From line In File.ReadLines(path) 
      Where line.Length <> 0 
' now you can enumerate all not-empty lines ' 
For Each line In lines 
    ' ... ' 
Next 

如果你坚持一个Streamreader

Using sr = New StreamReader(path) 
    While Not sr.EndOfStream 
     Dim line = sr.ReadLine() 
     If Not String.IsNullOrEmpty(line) Then 
      ' ... ' 
     End If 
    End While 
End Using 
+0

Tanx为快速反应和代码,但此代码只适用于当你读入的行是完全空的,但我有一个线,像这样(.85,14)其中所有其他值都丢失的值和错误也会发生,你是否也有解决方案。 – AntoonVs

+0

Tanx反应il看看你的链接 – AntoonVs

+0

tanx m8 nice link – AntoonVs

相关问题