如何在Javascript中以编程方式创建控制字符? [英] How do I make control characters programatically in Javascript?

查看:90
本文介绍了如何在Javascript中以编程方式创建控制字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Javascript中,我可以输入'\ u00A3'来使用其char代码获取字符。我可以用 String.fromCharCode(parseInt('00A3',16))以编程方式执行此操作。

In Javascript I can type '\u00A3' to get a character using its char code. I can do this programatically to with String.fromCharCode(parseInt('00A3', 16)).

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

But I can't find a way to do the same for a control character. I can type them in my source code but I want a way to generate them in code.

推荐答案

听起来像你可以只需使用此列表: http://en.wikipedia.org/wiki/C0_and_C1_control_codes 并使用在那里定义的字符点用 \u String.fromCharCode 插入它们,如你的例子所示?

Sounds to me like you could just use this list: http://en.wikipedia.org/wiki/C0_and_C1_control_codes and use the character points defined there to insert them with \u or String.fromCharCode as in your example?

PS:您可以使用文字: 0x00A3

PS: instead of the parseInt, you could use a literal: 0x00A3

这篇关于如何在Javascript中以编程方式创建控制字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆