转换大小写字母 如 abC 转为 ABc
let str = "zhufeng哈哈哈HAHAHA"
// "A".charCodeAt() 转为Unicode码
// console.log("A".charCodeAt())
str = str.replace(/[a-zA-z]/g,item => {
// 验证是否为大写字母:
// 转为大写字母看是否与原字符相等
// 对比ASCLL嘛 大写字母A-Z 为 65-90
/* if(item.charCodeAt() >= 65 && item.charCodeAt() <= 90) {
return item.toLowerCase()
}else {
return item.toUpperCase()
} */
return item.toUpperCase() === item ? item.toLowerCase() : item.toUpperCase();
})
console.log(str)