TextFieldParser.SetFieldWidths(Int32[]) Method

Definition

Sets the delimiters for the reader to the specified values.

C#
public void SetFieldWidths(params int[]? fieldWidths);
C#
public void SetFieldWidths(params int[] fieldWidths);

Parameters

fieldWidths
Int32[]

Array of Integer.

Examples

This example opens a text-field parser and defines the field width as 5.

VB
Using FileReader As New Microsoft.VisualBasic.FileIO.
    TextFieldParser("C:\logs\test.log")

    FileReader.SetFieldWidths(5)
End Using

Replace the path C:\logs\test.log with the path and name of the file you wish to parse.

The following example opens a text-field parser and defines the field widths as 5, 10, and variable.

VB
Using MyReader As New Microsoft.VisualBasic.FileIO.
    TextFieldParser("C:\logs\test.log")

    MyReader.SetFieldWidths(5, 10, -1)
End Using

Replace the path C:\logs\test.log with the path and name of the file you wish to parse.

Remarks

The existing contents of the Delimiters property are cleared when this is set.

This method provides a way to set delimiters without creating an array.

The following table lists example of tasks involving the SetFieldWidths method.

Applies to

Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also