简体   繁体   中英

Read non printable characters from Javascript

Say I have the following Javascript instruction:

var a="hiàja, c . Non di–gt";

a contains binary data, ie, any ASCII from 0-255. Before what ASCII bytes should I add backslash so that a is read properly? (for example, before " ).

Should I use an specific charset and content-type different than text/Javascript and UTF-8?

Thanks

The ASCII range is 0 to 127, but strings are not limited to ASCII in JavaScript. According to the ECMAScript standard, “All characters may appear literally in a string literal except for the closing quote character, backslash, carriage return, line separator, paragraph separator, and line feed.” If the encoding of your document is suitable (eg, windows-1252 or utf-8) and properly declared, you can use your example string as it is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM