fieldr

fieldr, function

def const pure fieldr(haystack: text, separator: text, n: number): text

Returns the nth field (zero-indexed, from the right) 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-d", "-", 2 |]
  [| "a", "-", 2 |]

T.Field = fieldr(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 d
a-b-c-d - 2 b
a–c-d - 2
a - 2

Remarks

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

See also

User Contributed Notes
0 notes + add a note