Converting lower & upper case ASCII characters

别等时光非礼了梦想. 提交于 2019-12-13 04:32:37

问题


I'm making a program that converts ascii characters 'a' through 'z' and 'A' through 'Z'. (only letters). for example, a+1 = b

a+2 = c

b+1 = c

A+1 = B

So the only thing I'm not sure how to do is mapping around. How can I make it so that when checklower/checkupper is true, to basically map around to the lower case letter (example, of z+2 = b).


回答1:


The simplest way is probably to use the % modulus operator:

int letter_add = ((input.at(i) - 'a' + cmd_int) % 26) + 'a';

You'll need a symmetrical line for capital letters (or just make the 'a' a variable too).



来源:https://stackoverflow.com/questions/18599230/converting-lower-upper-case-ascii-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!