1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > vb.net-读取定宽文本文件-比如日志

vb.net-读取定宽文本文件-比如日志

时间:2019-12-03 05:54:26

相关推荐

vb.net-读取定宽文本文件-比如日志

0001 /04/01 Y-werqwerqwerwe0002 /04/02 N-vvvad0003 /04/02 Y-sfasf0004 /04/02 Y-120005 /04/03 Y-23faas0006 /04/03 N-124140007 /04/03 Y-x以上类似的文本内容

在定宽文本文件中,结尾处的字段可以具有可变宽度。 若要指定结尾处的字段具有可变宽度,请将它定义为宽度小于或等于零。

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 SubEnd Class

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。