开发者

Converting ascii to text

开发者 https://www.devze.com 2023-02-20 13:16 出处:网络
How do I take an ascii code and convert it into its character using JavaScript?I\'m in a nested loop and need to label each loop 1A, 2A, 1B, 2B, etc, and I would like to avoid ha开发者_JS百科rd coding

How do I take an ascii code and convert it into its character using JavaScript? I'm in a nested loop and need to label each loop 1A, 2A, 1B, 2B, etc, and I would like to avoid ha开发者_JS百科rd coding every character using if statements.


You can use String.fromCharCode()

String.fromCharCode(ascii_value)

This is plain Javascript by the way. If you want to use hex numbers, convert them to decimal by using parseInt().

parseInt("ff", 16)

For example, this snippet takes the hex number ff and returns the character ÿ:

String.fromCharCode(parseInt("ff", 16))

0

精彩评论

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

关注公众号