Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 hard coding every character using if statements.

like image 463
twh Avatar asked Nov 15 '25 05:11

twh


1 Answers

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))
like image 187
jm_toball Avatar answered Nov 17 '25 17:11

jm_toball



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!