如何在Javascript中编程地制作控制字符

How do I make control characters programatically in Javascript?

本文关键字:控制字符 编程 Javascript      更新时间:2023-09-26

在Javascript中,我可以键入''u00A3'以使用其字符代码获得字符。我可以用String.fromCharCode(parseInt('00A3', 16))编程地做到这一点。

但是我找不到一种方法来为控制字符做同样的事情。我可以在源代码中输入它们但我想在代码中生成它们

听起来像我可以使用这个列表:http://en.wikipedia.org/wiki/C0_and_C1_control_codes并使用定义在那里的字符点插入它们与'uString.fromCharCode在你的例子?

PS:代替parseInt,你可以使用文字:0x00A3

您可以轻松嵌入八进制数:

var crlf = ''013' + ''012'; // octal numbers
alert('hello' + crlf + 'there'); // shows hello'n'rthere

对十六进制不起作用:

var clrf = ''0xD' + ''0xA'; // hex
alert('hello' + crlf + 'there'); // shows helloxDxAthere