Effacer les filtres
Effacer les filtres

Finding the first occurance of a given string

22 vues (au cours des 30 derniers jours)
UWM
UWM le 10 Nov 2016
Commenté : UWM le 11 Nov 2016
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?

Réponse acceptée

KSSV
KSSV le 11 Nov 2016
Modifié(e) : KSSV le 11 Nov 2016
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)
  1 commentaire
UWM
UWM le 11 Nov 2016
Thank you very much for help :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by