Visual Basic 中读取逗号分隔的文本文件

TextFieldParser 对象提供一种可以轻松而高效地分析结构化文本文件(如日志)的方法。 TextFieldType 属性用于定义文件是带分隔符的文件还是具有固定宽度文本字段的文件。

 

Dim currentRow As String()
   While Not MyReader.EndOfData
      Try
         currentRow = MyReader.ReadFields()
         Dim currentField As String
         For Each currentField In currentRow
            MsgBox(currentField)
         Next
         Catch ex As Microsoft.VisualBasic.
                     FileIO.MalformedLineException
           MsgBox("Line " & ex.Message &
           "is not valid and will be skipped.")
     End Try

https://docs.microsoft.com/zh-cn/dotnet/visual-basic/developing-apps/programming/drives-directories-files/how-to-read-from-text-files-with-multiple-formats
https://docs.microsoft.com/zh-cn/dotnet/visual-basic/developing-apps/programming/drives-directories-files/how-to-read-from-comma-delimited-text-files
posted @ 2019-12-18 13:50  流水江湖  阅读(514)  评论(0)    收藏  举报