part of file name
1 次查看(过去 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 个)
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!