- Find the first letter of each word.
- Capitalize it.
- Determine the length of each word, by finding the LAST letter of each word.
- If any word has length at least 3 letter, then capitalize the letter 2 after the first letter in that word.
How do you capitalize the first and the third letter of each word in a sentence?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tatiana Kobachishvili
el 21 de Sept. de 2021
Comentada: Cris LaPierre
el 21 de Sept. de 2021
How do I capitalizde the first and the third for in a sentence using functions?
Example: my pet is hungry
To >> My PeT Is HuNgry
1 comentario
John D'Errico
el 21 de Sept. de 2021
Editada: John D'Errico
el 21 de Sept. de 2021
Seems pretty easy.
All of the above is probably even doable using a vectorized set of operations if you are careful.
What is the problem? This seems trivial, at least at the most simplistic level.
You may need to be careful, in how you watch for the inter-word breaks. Is it only spaces that you need to look for, or is punctuation expected? How about a tab, or other classes of white space? Carriage returns? What about a comma, period, or semi-colon, exclamation mark, even a question mark? How about a word like "don't" where not all characters are letters? That might not be too bad, but then how about a shorter contraction like "I'll"? What is the third letter there? Could there be other characters? Numbers? Dashes? So clearly things could be made complicated, if your teacher decides to make it so. But you need to do the work.
But, since this is clearly a homework assignment, I'm not going to do your work for you with not a bit of effort shown by you.
Respuestas (2)
Cris LaPierre
el 21 de Sept. de 2021
There are different ascii codes for lowercase and uppercase letters (https://www.ascii-code.com/, see codes 65-122). I suspect the purpose of this assignment is to learn to use indexing to access and modify elements of a vector.
- Ch 4 - Vectors and Matricies
- Ch 5 - Indexing into and Modifying Arrays
2 comentarios
Cris LaPierre
el 21 de Sept. de 2021
Honestly, just forgot about the upper fucntion. There are many ways to solve this problem. This is just one.
Stephen23
el 21 de Sept. de 2021
Editada: Stephen23
el 21 de Sept. de 2021
T = 'my pet is hungry';
U = regexprep(T,'(?<=\<(\w{2})?)(\w)','${upper($1)}')
Of course because this is clearly homework you will not be able to hand in my answer as your own work.
Also note that teachers/tutors are perfectly capable of searching this forum:
0 comentarios
Ver también
Categorías
Más información sobre Function Creation 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!