vb.net2019-读取定宽文本文件-比如日志
生活随笔
收集整理的這篇文章主要介紹了
vb.net2019-读取定宽文本文件-比如日志
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
0001 2019/04/01 Y-werqwerqwerwe
0002 2019/04/02 N-vvvad
0003 2019/04/02 Y-sfasf
0004 2019/04/02 Y-12
0005 2019/04/03 Y-23faas
0006 2019/04/03 N-12414
0007 2019/04/03 Y-x
以上類似的文本內(nèi)容
在定寬文本文件中,結(jié)尾處的字段可以具有可變寬度。 若要指定結(jié)尾處的字段具有可變寬度,請(qǐng)將它定義為寬度小于或等于零。
Public Class Form1Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.ClickOpenFileDialog1.Filter = "Text Files(*.TXT)|*.TXT"If OpenFileDialog1.ShowDialog = DialogResult.OK ThenDim fileName As String = OpenFileDialog1.FileNameUsing Reader As New Microsoft.VisualBasic.FileIO.TextFieldParser(fileName)Reader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.FixedWidthReader.SetFieldWidths(5, 11, -1)Dim currentRow As String()While Not Reader.EndOfDataTrycurrentRow = Reader.ReadFields()Dim currentField As StringFor Each currentField In currentRowTextBox1.Text &= vbCrLf & currentFieldNextCatch ex As Microsoft.VisualBasic.FileIO.MalformedLineExceptionMsgBox("Line " & ex.Message & "is not valid and will be skipped.")End TryEnd WhileEnd UsingEnd IfEnd Sub End Class總結(jié)
以上是生活随笔為你收集整理的vb.net2019-读取定宽文本文件-比如日志的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 判断String为空 StringUti
- 下一篇: maven-compiler-plugi