How to search pathname for string

Hi,
I'm using this code to give the filepath of the selected file:
[FileName,PathName,FilterIndex] = uigetfile
PathName = T:\Field Test\Field Test Scripts\Master Files\For Single Screen File\Final Combined Script\OLD\
Now I want to search this pathname for 'OLD', so I used this code:
strcmpi(PathName, 'OLD')
But it always returns false:
ans =
0
What am I doing wrong?
Thanks,

 채택된 답변

José-Luis
José-Luis 2012년 8월 22일
편집: José-Luis 2012년 8월 22일

0 개 추천

You are comparing two strings for equality, and the comparison is not case sensitive (help strcmpi). What you wanted to do, I guess, is to find out if a string is included in another string. For that i would recommend:
isFound = ~isempty(regexp(Pathname,'OLD'));
Cheers!

댓글 수: 3

Aadil
Aadil 2012년 8월 22일
thanks a lot
José-Luis
José-Luis 2012년 8월 22일
My pleasure!
Faster:
isFound = strfind(Pathname, 'OLD')
Safer:
isFound = strfind(fullfile(Pathname, filesep), [filesep, 'OLD', filesep])
This avoids a false match for "C:\Temp\REINHOLD\newData\".

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

추가 답변 (0개)

카테고리

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

질문:

2012년 8월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by