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");
// output
2

strpos("abcdefg","d");
// output
3

strpos("abcdefg","ah");
// output
-1