Navigation :
field
field, function
def const pure field(haystack: text, separator: text, n: number): text
Returns the nth field (zero-indexed, from the left) in haystack, separated by
separator.
haystack: text to split.
separator: delimiter between fields.
n: zero-based field index.
Examples
table T = with
[| as Haystack, as Separator, as N |]
[| "a-b-c-d", "-", 0 |]
[| "a-b-c-d", "-", 2 |]
[| "a--c", "-", 1 |]
[| "a", "-", 2 |]
T.Field = field(T.Haystack, T.Separator, T.N)
show table "Fields" with
T.Haystack
T.Separator
T.N
T.Field
This produces the following table:
| Haystack |
Separator |
N |
Field |
| a-b-c-d |
- |
0 |
a |
| a-b-c-d |
- |
2 |
c |
| a–c |
- |
1 |
|
| a |
- |
2 |
|
If separator is empty or n is negative, field returns an empty text.
See also