String.NthField

From Xojo Documentation

Method

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.

Syntax

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.

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"

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

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, Split functions.