JS字符(字母)ASCII码转换方法

来源:互联网 发布:显卡稳定性测试软件 编辑:程序博客网 时间:2024/06/08 02:50

大写字母A 到Z 的值是从65 到90

小写a到z 是从91 到 122

字符转ascii码:用charCodeAt();
ascii码砖字符:用fromCharCode();


Welcome to this Kata. In this Kata you will be given a string. Your task is to replace every character with the letter following it in the alphabet (for example, "b" should be "c", "z" should be "a" and capital "Z" should be "A").

The test cases would not have any special symbols or numbers but it will have spaces. And the upper and lower cases should be retained in your output.

For Example:

letterChange('Lorem Ipsum')    // return Mpsfn Jqtvn

functionletterChange(str){  

return str.replace(/\w/g,function(c)

returnString.fromCharCode(  

c.charCodeAt(0) + (c != "Z" && c != "z" ? 1 : -25));  

});}

0 0
原创粉丝点击