finding indices in a string

Respuestas (2)

KSSV
KSSV el 16 de Dic. de 2016

0 votos

str = '123 0009 90' ;
idx = findstr(str,'0')

2 comentarios

may gor
may gor el 16 de Dic. de 2016
i need only the indices of '000' before the '9'(not the zero after the 9 in '90')
KSSV
KSSV el 16 de Dic. de 2016
It gives all the indices.....you can pick the first three, that's what you wanted..

Iniciar sesión para comentar.

Adam
Adam el 16 de Dic. de 2016

0 votos

idx = strfind( str, ' 0' );
will find you the start of each leading 0. Then you can count the zeros after each of those before a 'proper' number.
strsplit( str, ' ' );
will divide up your string into each component also, but getting the indices from that would be a tedious process so probably not too helpful.

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 16 de Dic. de 2016

Respondida:

el 16 de Dic. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by