1

現在、固定幅のテキスト ファイルを読み込んでいます。ループする代わりに、5 番目の値(fixedWidths を見ると 1 文字) を取得する方法はありますか?

これが私のコードのコピーです:

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
4

1 に答える 1