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 Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by