making upper case character with respect to the indexes
7 次查看(过去 30 天)
显示 更早的评论
indxC = [1,7];
s ='hello world';
i want s to be 'Hello World' with using the indxC. The indexes of c should be upper case in the string s. Can you help me thanks
0 个评论
采纳的回答
Image Analyst
2020-5-25
编辑:Image Analyst
2020-5-25
Try this:
indxC = [1,7];
s ='hello world';
s(indxC) = upper(s(indxC))
or more generally:
s ='hello world';
upperS = upper(s); % Create an ALL CAPITALS VERSION of s.
spaceLocations = find(s(1:end-1) == ' '); % Find spaces - we'll capitalize the location after a space.
spaceLocations = [0, spaceLocations] % Always capitalize the first letter, so prepend 0.
s(spaceLocations + 1) = upperS(spaceLocations + 1) % Replace these locations with upper case letters.
2 个评论
Image Analyst
2020-5-25
After copying and pasting, this is what I get:
s =
'Hello World'
So I don't know what you mean when you say that just the indexes are printed, and not 'Hello World'. Please post a screenshot.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!