finding indices in a string

how can i find the indices of the leading zeros in this string: '123 0009 90'

回答 (2 件)

KSSV
KSSV 2016 年 12 月 16 日

0 投票

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

2 件のコメント

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

サインインしてコメントする。

Adam
Adam 2016 年 12 月 16 日

0 投票

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.

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

タグ

質問済み:

2016 年 12 月 16 日

回答済み:

2016 年 12 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by