Find and count how many capital characters are in str, and then change them to lower cases USING LOOPS
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (3)
Rik
el 15 de Oct. de 2019
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 comentarios
Steven Lord
el 15 de Oct. de 2019
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 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements 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!