How can I print an Extended-ASCII character to the console. For instance if I use the following
puts 57.chr
It will print "9" to the console. If I were to use
puts 219.chr
It will only display a "?". It does this for all of the Extended-ASCII codes from 128 to 254. Is there a way to display the proper character instead of a "?".
On a standard 101 keyboard, special extended ASCII characters such as é or ß can be typed by holding the ALT key and typing the corresponding 4 digit ASCII code. For example é is typed by holding the ALT key and typing 0233 on the keypad.
A set of codes that extends the basic ASCII set. The basic ASCII set uses 7 bits for each character, giving it a total of 128 unique symbols. The extended ASCII character set uses 8 bits, which gives it an additional 128 characters.
Some people call any non-ASCII character in Unicode "extended ASCII". In other contexts only the UTF-8 encoding counts, and in yet other contexts no Unicode encoding is considered extended ASCII.
ASCII stands for “American Standard Code for Information Interchange”. You can find an ASCII table, or you can ask Ruby to convert characters to their ASCII value. If you have an integer you can get the associated character. As we’ll see later in this article, this range of characters is limited.
There are extended ASCII characters that are particularly useful when trying to make a textual user-interface (TUI). For example, when trying to make boxes and separators, like with the ┤ character (ASCII 180).
Starting with ASCII. ASCII stands for “American Standard Code for Information Interchange”. You can find an ASCII table, or you can ask Ruby to convert characters to their ASCII value. If you have an integer you can get the associated character. As we’ll see later in this article, this range of characters is limited. Why?
Encoding::ASCII_8BIT is a special encoding that is usually used for a byte string, not a character string. But as the name insists, its characters in the range of ASCII are considered as ASCII characters.
I am trying to using the drawing characters to create graphics in my console program.
You should use UTF-8 nowadays.
Here's an example using characters from the Box Drawing Unicode block:
puts "╔═══════╗\n║ Hello ║\n╚═══════╝"
Output:
╔═══════╗
║ Hello ║
╚═══════╝
So if for instance I was going to use the Unicode character U+2588 (the full block) how would I print that to the console in Ruby.
You can use:
puts "\u2588"
or:
puts 0x2588.chr('UTF-8')
or simply:
puts '█'
You may need to specify the encoding, e.g.:
219.chr(Encoding::UTF_8)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With