How to Change the first letter of a string to capital case and the rest to lowercase
古いコメントを表示
impropermsg = input('Enter the sentence : \n', 's');
function propermsg = changemsg(impropermsg)
propermsg = strcat(upper(impropermsg(1)),lower(impropermsg(2:end)));
end
% The user can input but nothing happens
3 件のコメント
Walter Roberson
2020 年 12 月 13 日
You are missing the step of invoking the function. You get the input and you define the function but not call the function on the input
Les Beckham
2020 年 12 月 13 日
You created a function that looks like it will do what you want but (at least in the code you posted) you never called the function.
You could just eliminate the 2nd and 4th lines of this code and you will have a simple two line script that does what you want (with the answer being in the propermsg string). If you want the result to be displayed, just take the semicolon off of the end of the propermsg = ... line.
sydney salvador
2020 年 12 月 16 日
採用された回答
その他の回答 (3 件)
mahmoud abdelaal
2022 年 10 月 3 日
移動済み: Image Analyst
2022 年 10 月 3 日
word='si'
new=replace(word,word(1),upper(word(1)))
1 件のコメント
That doesn't replace the rest with lower case like requested:
word='siUPPERCASE'
new=replace(word,word(1),upper(word(1)))
You'd need to add this line:
new = replace(new, word(2:end), lower(word(2:end)))
Toshiaki Takeuchi
2024 年 6 月 4 日
編集済み: Walter Roberson
2024 年 6 月 5 日
str = "test";
pat = lineBoundary("start")+lettersPattern(1);
new_str = replace(str,pat,(upper(extract(str,pat))))
1 件のコメント
Walter Roberson
2024 年 6 月 5 日
This misses on the "convert the rest to lowercase"
カテゴリ
ヘルプ センター および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!