Find string ends with xls or xlsx
Mostra commenti meno recenti
I have a char array of strings (each string is a file name) and I would like to find out the strings that ends with xls or xlsx. I know that strcmp can be used only if to compare the first few characters, which is the opposite of what I intent to do---compare the last few characters.
What should I do in this case? Thank you.
Risposta accettata
Più risposte (1)
Star Strider
il 13 Lug 2016
The findstr function may do what you want:
fn = 'filename.xlsx';
xls_pos = findstr(fn,'xls')
xls_pos =
10
So if ‘xls_pos’ (in this example) is not empty, the string contains ‘xls’ or ‘xlsx’.
2 Commenti
chlor thanks
il 13 Lug 2016
Modificato: chlor thanks
il 13 Lug 2016
Star Strider
il 13 Lug 2016
My pleasure!
Categorie
Scopri di più su Data Type Conversion in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!