write a math lab function that takes a string of characters as input argument and returns a string in which each vowel and consonant of the input string have been replaced by 'v' and 'c' respectively

답변 (1개)

Here is a solution in just one line using one regexprep call:
>> str = 'the quick brown fox';
>> out = regexprep(str,{'(?![aeiou])[a-z]','[aeiou]'},{'c','v'},'ignorecase')
out =
ccv cvvcc ccvcc cvc
Note that it correctly identifies only consonants and vowels: non-alphabetical characters are simply returned unchanged:
>> str = '123: Hello, World!';
>> out = regexprep(str,{'(?![aeiou])[a-z]','[aeiou]'},{'c','v'},'ignorecase')
out =
123: cvccv, cvccc!

카테고리

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

질문:

2016년 5월 6일

편집:

2016년 5월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by