- 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 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
John D'Errico
2021 年 9 月 21 日
編集済み: John D'Errico
2021 年 9 月 21 日
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.
回答 (2 件)
Cris LaPierre
2021 年 9 月 21 日
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 件のコメント
Cris LaPierre
2021 年 9 月 21 日
Honestly, just forgot about the upper fucntion. There are many ways to solve this problem. This is just one.
Stephen23
2021 年 9 月 21 日
編集済み: Stephen23
2021 年 9 月 21 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!