开发者

Converting ascii to text

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜