Condense code in Split string operation
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a excel file with the name 'xxx_yyy_zzz.xlsx'
Here, I want to extract only the part 'zzz' and for that I am using the following code
name = 'xxx_yyy_zzz.xlsx';
dummy1 = split('xxx_yyy_zzz.xlsx', '.');
dummy2 = split(dummy1{1}, '_');
final = dummy2{end};
My question is -- is it posible to condense these four lines into a single line of code?
Thanks
SD
댓글 수: 0
채택된 답변
추가 답변 (1개)
Les Beckham
2022년 9월 13일
If you put the filename in a string instead of a char vector you can do it in one line
s = "xxx_yyy_zzz.xlsx"
extractBetween(s, '_', '_')
If it is a char vector it will take two lines
s = 'xxx_yyy_zzz.xlsx'
s1 = extractBetween(s, '_', '_')
s2 = s1{:}
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!