How to read only vowels of a string

조회 수: 5 (최근 30일)
Balkar Singh
Balkar Singh 2020년 4월 24일
댓글: Balkar Singh 2020년 4월 27일
How can I read only vowels of a string by using regular expression in matlab. Thanks in advance.

채택된 답변

Tommy
Tommy 2020년 4월 24일
편집: Tommy 2020년 4월 24일
>> regexprep('How to read only vowels of a string?', '[^aeiouAEIOU]', '')
ans =
'ooeaooeoai'
>> char(regexp('How to read only vowels of a string', '[aeiouAEIOU]', 'match'))'
ans =
'ooeaooeoai'
(edit) No longer ignoring capitals!
  댓글 수: 6
Tommy
Tommy 2020년 4월 26일
Certainly, if you have the trimmed down character vector:
vowels = regexprep('How to read only vowels of a string?', '[^aeiouAEIOU]', '')
%{
vowels =
'ooeaooeoai'
%}
you could use histc:
bins = sort('aeiouAEIOU');
counts = histc(double(vowels), double(bins));
for v = bins
fprintf('%c: %d\n', v, counts(bins==v));
end
%{
A: 0
E: 0
I: 0
O: 0
U: 0
a: 2
e: 2
i: 1
o: 5
u: 0
%}
Balkar Singh
Balkar Singh 2020년 4월 27일
Thanks Sir.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by