开发者

How to reverse String.fromCharCode?

开发者 https://www.devze.com 2022-12-16 06:53 出处:网络
String.fromCharCode(72) gives H. How开发者_高级运维 to get number 72 from char H?\'H\'.charCodeAt(0)

String.fromCharCode(72) gives H. How开发者_高级运维 to get number 72 from char H?


'H'.charCodeAt(0)


Use charCodeAt:

var str = 'H';
var charcode = str.charCodeAt(0);


@Silvio's answer is only true for code points up to 0xFFFF (which in the end is the maximum that String.fromCharCode can output). You can't always assume the length of a character is one:

'
0

精彩评论

暂无评论...
验证码 换一张
取 消