strtake(X;Y;N)

Returns the first number of characters, or the substring consisting of the first number of elements delimited by a particular value, within a given string.

Syntax

strtake(X;Y;N)
bstrtake(X;Y;N)

Input

Argument Type Description
X text The string on which to apply the function

A scalar value or the name of a column

Y text Y is the character or string to be used as the delimiter in X

A scalar value or the name of a column

N integer An index corresponding to the number of elements to take from X

The index N is 1-based (i.e., the first occurrence has index 1).

A negative index counts back from the end of the string (i.e., N=-1 refers to the last element or character).

Return Value

If Y is non-empty, this function splits the string X using Y as a delimiter and returns a Y-delimited list of the first N elements. If Y is empty, it returns the first N characters of X.

If X or N is N/A, the result is N/A. If Y is N/A, the result is the first N characters of X.

Sample Usage

value delimiter index strtake(value;delimiter;index)
'apple,banana,cherimoya' ',' 2 'apple,banana'
'foo--bar--baz' '--' -1 'baz'
'foo--bar--baz' '' 4 'foo-'

Additional Information

  • strtake is Unicode (UTF-8) compliant and will work with Unicode or plain ASCII text fields.
  • If passed a string argument that is not legal Unicode, it will by default signal an error (configurable as a user preference).
  • A corresponding function bstrtake can be used with non-Unicode strings (e.g., binary or legacy encodings).