Finding the first occurance of a given string

I have a large text file in which I need to find the first occurance of a given string, e.g. 'STAX'. How can I do this?

 채택된 답변

KSSV
KSSV 2016년 11월 11일
편집: KSSV 2016년 11월 11일

0 개 추천

fid = fopen('filename','r') ;
S = textscan(fid,'%s','Delimiter','\n');
S = S{1} ;
%%Get the line number of your string 'STAX'
idxS = strfind(S,'STAX'); % find the index of your string
idx = find(not(cellfun('isempty',idxS))); % your required indices
S(idx)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

UWM
2016년 11월 10일

댓글:

UWM
2016년 11월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by