Find and count how many capital characters are in str, and then change them to lower cases USING LOOPS
4 次查看(过去 30 天)
显示 更早的评论
how to do this with loops i know the regular way but i want to know with loops
please if you can help then do
but dont comment if you will just make random comments and not help
please
thank you
0 个评论
回答(3 个)
Rik
2019-10-15
You can easily do this without loops:
s = 'This is my String with CapiTal LETTERS in it. Let''s change them to lowercase uSiNg LoOpS.'
s_out=lower(s);
N_upper_case=sum(s~=s_out);
If for some strange reason you insist on doing this with loops, you can easily add some indexing:
s = 'This is my String with CapiTal LETTERS in it. Let''s change them to lowercase uSiNg LoOpS.'
s_out=s;
N_upper_case=0;
for n=1:numel(s)
s_out(n)=lower(s_out(n));
N_upper_case=N_upper_case+double(s_out(n)~=s(n));
end
If you ask me the second option is much more complex (and slower) than the first, without getting any benefits.
0 个评论
Steven Lord
2019-10-15
The isstrprop function can help you identify which characters are upper-case, which are lower-case, and which are neither. After that, your loop simply needs to see if the current letter is a different case than the next letter. Since I suspect this is a homework assignment I'm not going to give you the implementation; you should be able to complete it given these hints. If you can't, show us what you've written and ask a specific question about where you're having difficulty and we may be able to provide you with additional guidance.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!