part of file name
2 ビュー (過去 30 日間)
古いコメントを表示
If I have a file name such as ' Hello_World_2020 ', I want to take the part between the underscores ' world ', how I would do that.
Regards.
0 件のコメント
採用された回答
Walter Roberson
2019 年 7 月 18 日
編集済み: Walter Roberson
2019 年 7 月 18 日
s = 'Hello_World_2020';
c = regexp(s, '_', 'split') ;
c{2}
You can also use strsplit() instead of regexp. On the other hand, strsplit() invokes regexp internally.
3 件のコメント
Adam Danz
2019 年 7 月 19 日
"If I write s=Hello_World_year_2020. the answer would be 'Hallo_year'. what I should modify?"
- "Hello_World_2020" --> "World": This removes everything before and after the underscores, including the underscores.
- "Hello_World_year_2020" --> "Hello_year": This doesnt' follow that rule.
I think Walter's solution will come in handy but you'll need to explain the rule you're following.
その他の回答 (3 件)
Adam Danz
2019 年 7 月 18 日
s = 'Hello_World_2020';
c = regexp(s,'_(.*)_','tokens');
c = c{1}{1};
c =
'World'
madhan ravi
2019 年 7 月 18 日
s=' Hello_World_2020 ';
[~,Wanted]=regexp(s,'_(.*)_','match','tokens');
Wanted{:}
2 件のコメント
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!