我目前正在阅读一个具有固定宽度的文本文件。除了循环,有没有办法让我们说第五个值(如果你看一下固定宽度,这是一个字符)?
这是我的代码的副本:
Private Function processPaymentRow(currentLine As String)
Dim result As String()
Using strStream As New StringReader(currentLine)
Using MyReader As New TextFieldParser(strStream)
MyReader.TextFieldType = FieldType.FixedWidth
'Set proper field widths for the payment row here
MyReader.FieldWidths = {10, 1, 10, 8, 1, 20, 13, 1, 8, 8, 8, 40,
40, 40, 40, 40, 25, 2, 9, 40, 10, 20, 6}
Try
result = MyReader.ReadFields()
'Dim currentField As String
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & "is not valid and will be skipped.")
End Try
End Using
End Using
For Each itm In result
MsgBox(itm & " Pay")
'// I can loop through the results and get the value I want.
Next
Return result
End Function