Filter löschen
Filter löschen

How to read only vowels of a string

1 Ansicht (letzte 30 Tage)
Balkar Singh
Balkar Singh am 24 Apr. 2020
Kommentiert: Balkar Singh am 27 Apr. 2020
How can I read only vowels of a string by using regular expression in matlab. Thanks in advance.

Akzeptierte Antwort

Tommy
Tommy am 24 Apr. 2020
Bearbeitet: Tommy am 24 Apr. 2020
>> 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 Kommentare
Tommy
Tommy am 26 Apr. 2020
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 am 27 Apr. 2020
Thanks Sir.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by