关闭

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

4788人阅读 评论(0) 收藏 举报
分类:

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

});}

0
1

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:28565次
    • 积分:549
    • 等级:
    • 排名:千里之外
    • 原创:21篇
    • 转载:32篇
    • 译文:0篇
    • 评论:0条
    文章分类