Find string ends with xls or xlsx

8 views (last 30 days)
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.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 13 Jul 2016
Edited: Azzi Abdelmalek on 13 Jul 2016
str='abc.xlsx xls.m df.xls er.doc sd.xls'
chlor thanks
chlor thanks on 14 Jul 2016
Thank you both! Especially for the notes Guillaume I really appreciate it!

Sign in to comment.

More Answers (1)

Star Strider
Star Strider on 13 Jul 2016
The findstr function may do what you want:
fn = 'filename.xlsx';
xls_pos = findstr(fn,'xls')
xls_pos =
So if ‘xls_pos’ (in this example) is not empty, the string contains ‘xls’ or ‘xlsx’.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by