strpos

Syntax

strpos(X, str)

Details

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

Parameters

X is a string scalar/vector.

str is a string scalar/vector.

Returns

If X contains str, returns the start position of str in X. Otherwise, returns -1.

Examples

strpos("abcdefg","cd");
// output: 2

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

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