strfind(X;Y;I)

Returns the position within a given string of a particular occurrence of a given substring.

Syntax

strfind(X;Y;I)
bstrfind(X;Y;I)

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 substring to find in X.

A scalar value or the name of a column

I integer An index corresponding to the particular occurrence of Y to find

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

A negative index counts back from the end of the string (i.e., I=-1 refers to the last occurrence).

Return Value

Returns an integer value corresponding to the position of the I'th occurrence of the substring Y within the string X.

Returns N/A if there is no I'th occurrence.

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

Sample Usage

value substring index strfind(value;substring;index)
'banana' 'an' 2 4
'banana' 'an' -2 2
'banana' 'an' 4
'banana' '' 2
'' 'an' 2

Additional Information

  • strfind 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 bstrfind can be used with non-Unicode strings (e.g., binary or legacy encodings).