Skip to content

strmatch

strings · scripts/strings/strmatch.m

: idx = strmatch (s, A)
: idx = strmatch (s, A, "exact")

Find the entries of A that start with s. This function is kept for old code only; new code should use strncmp or strcmp. The first call issues warning ("nexus:deprecated:strmatch", …).

A may be a string, a character matrix (one entry per row) or a cell array of strings. The result is a column of the indices of the matching entries. Trailing blanks and null characters are ignored on both sides. With the option "exact" an entry must equal s, not merely begin with it.

strmatch ("pine", "pineapple")
     ⇒  1
strmatch ("pine", ["pine     "; "pineapple"; "a pine   "])
     ⇒  [1; 2]
strmatch ("pine", ["pine     "; "pineapple"; "a pine   "], "exact")
     ⇒  1

Depending on the task, strncmp, strcmp, regexp or validatestring will usually be a clearer replacement.