To find names that end with extensions, create a pattern that matches a period followed by letters by using the lettersPattern function. (You can build up a complex pattern by combining simple patterns in expressions. Such expressions can also include literal text, like "." in this example.)
pat = "." + lettersPattern
pat = pattern
Matching:
"." + lettersPattern
Return a logical array indicating which names end with extensions.
TF = endsWith(str,pat)
TF = 2×3 logical array
1 1 0
1 1 0
Display the matching names.
str(TF)
ans = 4×1 string
"abstract.docx"
"data-analysis.ppt"
"data.tar.gz"
"results.ptx"
Find the names with extensions that are exactly three letters long.
pat = "." + lettersPattern(3);
TF = endsWith(str,pat);
str(TF)
ans = 2×1 string
"data-analysis.ppt"
"results.ptx"
For a list of functions that create pattern objects, see pattern.
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window.
Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.