Method Reference: string.erase

string: newstr = erase (str, match)

Remove content from string array.

newstr = erase (str, match) removes the occurrences of match from each element of the string array str. match can be a string array, a character vector, or a cell array of character vectors. When match contains more than one piece of text, every occurrence of every element of match is removed. newstr is a string array of the same size as str; the size of match need not match the size of str. Missing values in str are preserved.

Source Code: string

Example: 1

erase deletes every occurrence of a substring from each string.

 files = string ({'cat.txt'; 'dog.txt'})
files =
  2x1 string array

    "cat.txt"    
    "dog.txt"
 erase (files, '.txt')
ans =
  2x1 string array

    "cat"    
    "dog"