strpos

Syntax

strpos(X, str)

Arguments

X is a string scalar/vector.

str is a string scalar.

Details

If X contains str, return the index in X where the first occurrence of str starts; otherwise, return -1.

Examples

$ strpos("abcdefg","cd");
2

$ strpos("abcdefg","d");
3

$ strpos("abcdefg","ah");
-1