From Xojo Documentation

Revision as of 12:25, 25 September 2020 by PLefebvre (talk | contribs) (See Also)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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


result=stringVariable.NthField(separator, fieldNumber)

Part Type Description
result String The field value desired.
stringVariable String The string that contains the desired field, with the field separated by the Separator string.
separator String The string that delimits the fields of data.
fieldNumber Integer The field number of the desired field. The first field is numbered 1.


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.

Using NthField in a loop to extract fields from a string is inefficient. You should use String.Split for this purpose.


This example returns "Smith"

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

This example demonstrates the use of a multiple character separator.

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

See Also

String.CountFields, String.LastField, String.Split functions.