Problem in displaying a substring

Problem in displaying a substring
Ex: I have this line:-
C:\abc\xyz\myName_1.wav
I want to display only 'myName' from this line

 채택된 답변

Junaid
Junaid 2011년 12월 30일

3 개 추천

Dear.. there can be multiple way. The easy way I think is to parse the string by dividing into tokens. Here is example you requested. lets say your string is in variable a;
a ='C:\abc\xyz\myName_1.wav';
strtok(fliplr(strtok(fliplr(strtok(a,'.')),'\')),'_')

추가 답변 (1개)

Grzegorz Knor
Grzegorz Knor 2011년 12월 30일

1 개 추천

doc fileparts
doc strfind

댓글 수: 2

Grzegorz Knor
Grzegorz Knor 2011년 12월 30일
In your case:
[pathstr, name, ext] = fileparts('C:\abc\xyz\myName_1.wav')
idx = strfind(name,'_')
disp(name(1:idx-1))
Nishat Anjum Shaikh
Nishat Anjum Shaikh 2011년 12월 30일
thanks!!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by