Method Reference: string.contains

string: TF = contains (str, pattern)
string: TF = contains (str, pattern, 'IgnoreCase', true)

Test if strings contain pattern.

TF = contains (str, pattern) returns a logical array TF of the same size as A containing true for each corresponding element of str that contains the specified pattern and false otherwise. Similarly to NaN values, <missing> elements do not match any pattern and always return false.

TF = contains (str, pattern, 'IgnoreCase', true) ignores case when determining if str ends with pattern.

Source Code: string

Example: 1

contains tests, element-wise, whether each string contains a substring.

 files = string ({'cat.txt'; 'dog.csv'; 'fish.txt'})
files =
  3x1 string array

    "cat.txt"     
    "dog.csv"     
    "fish.txt"
 contains (files, '.txt')
ans =

  1
  0
  1