Borrar filtros
Borrar filtros

Finding the first occurance of a given string

22 visualizaciones (últimos 30 días)
UWM
UWM el 10 de Nov. de 2016
Comentada: UWM el 11 de Nov. de 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?

Respuesta aceptada

KSSV
KSSV el 11 de Nov. de 2016
Editada: KSSV el 11 de Nov. de 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)

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by