字符大小写及ASCII码转化方法

发布时间 2023-08-21 13:59:07作者: weimiu

大小写转化:

("HelloWorld").toLowerCase();  // helloworld
("HelloWorld").toUpperCase(); // HELLOWORLD

字符与ASCII码:

("A").charCodeAt();   // 65
String.fromCharCode(65); // A

将大写字母转换为小写字母的后一位字母,Z转化为a;

let str = "AJIZDJI";
let arr = str.split('').map((item,i)=>{
if(item == 'Z') {
return 'a';
} else {
return String.fromCharCode(item.charCodeAt()+1).toLowerCase();
}
})
console.log(arr.join('')); // bkjaekj





参考:字符大小写及ASCII码转化方法