前言
本文介绍,如何将字符转化为ascii码,以及如何将ascii码转化为字符的方法,以及常用字符ascii码位置和小示例。
图
字符转化为ascii码
可以知道:
0-9
的ascii码在48-57
,A-Z
的ascii码在65-90
,a-z
的ascii码在97-122
。
'0'.charCodeAt() // 48
'9'.charCodeAt() // 57
'A'.charCodeAt() // 65
'Z'.charCodeAt() // 90
'a'.charCodeAt() // 97
'z'.charCodeAt() // 122
ascii码转字符
String.fromCodePoint(48) // 0
String.fromCodePoint(57) // 9
String.fromCodePoint(65) // A
String.fromCodePoint(90) // Z
String.fromCodePoint(97) // a
String.fromCodePoint(122) // z
使用小示例
1转化为A,2转化为B
String.fromCodePoint('1'.charCodeAt() + 16) // A
String.fromCodePoint('2'.charCodeAt() + 16) // B
尾言
如果本文对你有帮助的话~欢迎点赞收藏,有什么问题或者建议,也欢迎提出,感谢。