Method Reference: string.startsWith

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

Test if strings start with pattern.

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

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

Source Code: string

Example: 1

startsWith tests whether each string begins with a given prefix.

 files = string ({'img_1'; 'img_2'; 'doc_1'})
files =
  3x1 string array

    "img_1"    
    "img_2"    
    "doc_1"
 startsWith (files, 'img')
ans =

  1
  1
  0