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

大写字母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

function letterChange(str) {  

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

return String.fromCharCode(  

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

});}

阅读更多
个人分类: js
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭