Method

NthField


Warning

This item was deprecated in version 2019r2. Please use String.NthField as a replacement.

Description

Returns a field from a row of data. The first field is numbered 1. If you need to parse binary data, use MemoryBlock instead.

Usage

result=NthField(source, separator, fieldNumber)

OR

result=stringVariable.NthField(separator, fieldNumber)

Part

Type

Description

result

String

The field value desired.

source

String

The string that contains the desired field, with the field separated by the Separator string.

separator

String

The string that separates columns of data.

fieldNumber

Integer

The column number of the desired field. The first field is numbered 1.

stringVariable

String

Any variable of type String.

Notes

The NthField function returns the field value from the source that precedes the fieldNumber occurrence of the separator in the source.

The separator may be a string of any length.

If fieldNumber is out of bounds, an empty string is returned. NthField is not case-sensitive. .. note:: Using NthField in a loop to extract fields from a string is inefficient. You should use String.Split for this purpose.

Sample code

This example returns "Smith"

Dim field As String
field = NthField("Dan*Smith*11/22/69*5125554323*Male", "*", 2)

Using the second syntax:

Dim s, field As String
s = "Dan*Smith*11/22/69*5125554323*Male"
field = s.NthField("*", 2)
MsgBox(field)

This example demonstrates the use of a multiple character separator.

Dim days As String = "Monday--Tuesday--Wednesday--Thursday--Friday--Saturday--Sunday"
Dim theDay As String = NthField(days, "--", 3)  ' sets theDay to "Wednesday"

Compatibility

All project types on all supported operating systems.