How to capitalize words in a string (matlab)

Hi, I am trying to capitalize a word in a string
For example, the structionn tells you to capitalize the word 'Mello' and lowercase the word 'Hello'.
in = ['Hello Mello Jello Mello Hello']
I want to return this: in = 'hello MELLO Jello MELLO hello'
strrep() function is banned here..I need to used something else

댓글 수: 4

Fangjun Jiang
Fangjun Jiang 2020년 5월 29일
how do you decide which word? I assume you know uppper() and lower().
gmltn1212
gmltn1212 2020년 5월 29일
편집: gmltn1212 2020년 5월 29일
lets say the instruction tells you to convert Hello to hello and Mello to MELLO
the cyclist
the cyclist 2020년 5월 29일
편집: the cyclist 2020년 5월 29일
Code is used to do repeatable tasks, according to rules. If you cannot tell us the exact rule to use, we cannot write code to do it.
Think about it. Suppose next time you tell me to convert "Hello" to "HeLLo" and "Mello" to "mELLO"?
It is impossible to write code for every possibility, for any input string. You need to be more specific.
gmltn1212
gmltn1212 2020년 5월 29일
I edited it. thanks

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

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 5월 29일

0 개 추천

"strrep() function is banned here". What about regexprep
in = 'Hello Mello Jello Mello Hello';
out = regexprep(in, {'hello', 'mello'}, {'hello', 'MELLO'}, 'ignorecase')
Result
out =
'hello MELLO Jello MELLO hello'

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2020년 5월 29일

답변:

2020년 5월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by