NthField

From Xojo Documentation

(Redirected from String.NthField)
Method

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

Syntax

result=NthField(source, separator, fieldNumber)
OR
result=stringVariable.NthField(separator, fieldNumber) Introduced 5.0

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.

fa-info-circle-32.png
Using NthField in a loop to extract fields from a string is inefficient. You should use Split for this purpose.

Examples

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 wed As String = NthField(days, ",", 3) // sets wed to "Wednesday"

See Also

CountFields, NthFieldB, Split functions.