Find string ends with xls or xlsx
3 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
Azzi Abdelmalek
2016 年 7 月 13 日
編集済み: Azzi Abdelmalek
2016 年 7 月 13 日
str='abc.xlsx xls.m df.xls er.doc sd.xls'
out=regexp(str,'\S+\.xlsx?\>','match')
6 件のコメント
Guillaume
2016 年 7 月 14 日
I would use this simpler regex:
regexp(str, '\.xlsx?$', 'match', 'once')
Matches '.xls', followed by an optional 'x', followed by the end of the string.
その他の回答 (1 件)
Star Strider
2016 年 7 月 13 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で String Parsing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!