upper case need help
1 次查看(过去 30 天)
显示 更早的评论
function unscramble=latinCipher(scramble)
[str,shift]=strtok(scramble,' ');
shift=str2num(shift);
str=char(mod(double(str)-97+shift,26)+97);
unscramble=upper(str);
end
for my this code, if I put lowercase 'sknz 4' it will output as 'WORD'. How could be fixed by puting uppercase 'SKNZ 4' would output as 'WORD". Because for now if I input 'SKNZ 4' it showed an unexpected value.
0 个评论
采纳的回答
Walter Roberson
2020-5-26
str=char(mod(double(lower(str))-97+shift,26)+97);
3 个评论
Walter Roberson
2020-5-26
Your input might be either upper case or lower case, and you want the two to be treated the same way, and the rest of your code assumes it was lower case. That makes the easiest approach to just use lower() to convert uppercase to lowercase (leaving lowercase alone.)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!