最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to render extended ASCII characters in terminal using nodejs - Stack Overflow

programmeradmin4浏览0评论

According to this site, ASCII extended character codes 176, 177 and 178 correspond to three characters consisting in different shades of rectangles:

Here in more detail, character 178:

Now, according to , I should be able to escape any ASCII character with a code below 256 with, for example, its hex escape sequence. So, 176 would be \xB0 in hex. But instead of getting the expected character as described above, I get "degree symbol" '°'. Degree symbol is ASCII 248, not 176, so.... what am I doing wrong?

According to this site, ASCII extended character codes 176, 177 and 178 correspond to three characters consisting in different shades of rectangles:

Here in more detail, character 178:

Now, according to https://mathiasbynens.be/notes/javascript-escapes, I should be able to escape any ASCII character with a code below 256 with, for example, its hex escape sequence. So, 176 would be \xB0 in hex. But instead of getting the expected character as described above, I get "degree symbol" '°'. Degree symbol is ASCII 248, not 176, so.... what am I doing wrong?

Share Improve this question edited Jul 2, 2017 at 21:55 jotadepicas asked Jul 2, 2017 at 21:43 jotadepicasjotadepicas 2,5033 gold badges29 silver badges48 bronze badges 1
  • The key point is "IBM developed an extension of 8-bit ASCII code, called "code page 437"". It's one of many extensions. kunststube/encoding – Bergi Commented Jul 2, 2017 at 22:04
Add a ment  | 

2 Answers 2

Reset to default 4

JavaScript uses Unicode, rather than extended ASCII. You can find the Unicode equivalent of the ASCII symbols by using String.prototype.charCodeAt(), and then output them with String.prototype.fromCharCode():

console.log("░".charCodeAt(0)); // 9617
console.log("▒".charCodeAt(0)); // 9618
console.log("▓".charCodeAt(0)); // 9619

console.log(String.fromCharCode(9617)); // ░
console.log(String.fromCharCode(9618)); // ▒
console.log(String.fromCharCode(9619)); // ▓

Hope this helps! :)

JavaScript deals in Unicode, not Extended ASCII.

U+00B0 is the degree symbol

Block elements hold positions 2580 to 259F

console.log("\u2592");

发布评论

评论列表(0)

  1. 暂无评论