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.

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

Remarks

If separator is empty or n is negative, field returns an empty text.

See also

User Contributed Notes
0 notes + add a note