Borrar filtros
Borrar filtros

How to capitalize words in a string (matlab)

2 visualizaciones (últimos 30 días)
gmltn1212
gmltn1212 el 29 de Mayo de 2020
Respondida: Ameer Hamza el 29 de Mayo de 2020
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 comentarios
the cyclist
the cyclist el 29 de Mayo de 2020
Editada: the cyclist el 29 de Mayo de 2020
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 el 29 de Mayo de 2020
I edited it. thanks

Iniciar sesión para comentar.

Respuestas (1)

Ameer Hamza
Ameer Hamza el 29 de Mayo de 2020
"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'

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by