endsWith

Tests whether text ends with a given piece of text or pattern.

Category: Language Fundamentals > Data Types

Syntax

tf = endsWith(str, suffix)

True where str ends with suffix.

tf = endsWith(str, suffix, 'IgnoreCase', true)

Ignores letter case.

Description

The test is case sensitive by default. An empty suffix always matches. It is the usual way to select files by extension: endsWith(names, '.m').

The counterpart for the beginning of the text is startsWith.

Input arguments

str
Character vector, string array or cell array of character vectors.
suffix
Text, a list of text (true if any matches), or a pattern.
'IgnoreCase'
Logical, default false.

Output arguments

tf
Logical array with the size of str.

Example

Extensions

endsWith({'a.m','b.txt','c.M'}, '.m')
endsWith("File.M", ".m", 'IgnoreCase', true)
endsWith('abc123', digitsPattern)
Output
ans = 1×3 logical array

   1   0   0
ans = logical
   1
ans = logical
   1

See also

startsWith contains strfind regexp