count number of occurences of character in string?

Is there a function/method for counting the number of times a specific character occurs in a string? Say
v = '30.44.532.56';
This is obviously nonesense, but I would like to check how many times the decimal point occurs so that I can reject if used with a function I wrote. This value would be input into GUIDE gui I am creating, so this is why it's in string format.

답변 (3개)

Dharanee dharan Mani
Dharanee dharan Mani 2020년 5월 3일

3 개 추천

Try using
countnum= count(v,'.');
Leor Greenberger
Leor Greenberger 2011년 9월 25일

1 개 추천

I suppose this will actually work.
v = '30.44.532.56';
length(strfind(v,'.'))

카테고리

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

태그

질문:

2011년 9월 25일

답변:

2020년 5월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by