Unit2-charCode字串大小寫轉換


chrome terminal 執行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
let str = 'hELLo';
let ans = '';

// console.log(String.fromCharCode(65, 90,97, 122));

for(let i = 0; i < str.length; i++) {
let temp = str.charCodeAt(i)
// console.log(temp);
if(temp >= 65 && temp <= 90) {
ans += String.fromCharCode(temp + 32);
} else {
if (temp >= 97 && temp <= 122) {
ans += String.fromCharCode(temp - 32);
}
else {
ands += str[i];
}
}
}

console.log('ans', ans);

Author: Jayson-Zheng
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source Jayson-Zheng !
  TOC