upper case need help

조회 수: 3 (최근 30일)
Maria
Maria 2020년 5월 26일
댓글: Image Analyst 2020년 5월 26일
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.

채택된 답변

Walter Roberson
Walter Roberson 2020년 5월 26일
str=char(mod(double(lower(str))-97+shift,26)+97);
  댓글 수: 3
Walter Roberson
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.)
Image Analyst
Image Analyst 2020년 5월 26일
Please "Accept this answer" to give Walter reputation points to thank him.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by