从 Javascript 读取不可打印的字符
假设我有以下 Javascript 指令:
var a="hiàja, c .非 di–g t";
a 包含二进制数据,即 0-255 之间的任何 ASCII。 我应该在哪些 ASCII 字节之前添加反斜杠以便正确读取 a ? (例如,在 " 之前)。
我应该使用与 text/Javascript 和 UTF-8 不同的特定字符集和内容类型吗?
谢谢
Say I have the following Javascript instruction:
var a="hiàja, c . Non di–g t";
a contains binary data, i.e., 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ASCII 范围是 0 到 127,但 JavaScript 中的字符串不限于 ASCII。根据 ECMAScript 标准,“除了结束引号字符、反斜杠、回车符、行分隔符、段落分隔符和换行符之外,所有字符都可以按字面意思出现在字符串文字中。”如果文档的编码合适(例如 windows-1252 或 utf-8)并且声明正确,则可以按原样使用示例字符串。
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 (e.g., windows-1252 or utf-8) and properly declared, you can use your example string as it is.