Skip to content

endsWith

strings · scripts/strings/endsWith.m

: retval = endsWith (str, pattern)
: retval = endsWith (str, pattern, "IgnoreCase", ignore_case)

Test whether strings finish with a given ending.

str is a string or a cell array of strings and pattern is a string or a cell array of strings. The result is a logical array of the same shape as str that is true wherever the string ends with at least one of the patterns.

The comparison respects letter case unless the option "IgnoreCase" is set to true.

endsWith ("report.pdf", ".pdf")
      ⇒   1
endsWith ("report.PDF", ".pdf")
      ⇒   0
endsWith ("report.PDF", ".pdf", "IgnoreCase", true)
      ⇒   1
endsWith ({"a.c", "b.h", "c.py"}, {".c", ".h"})
      ⇒   1  1  0