Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要从字符串中删除“↵”字符,但我从 RegExp 中得到了一些奇怪的行为。有人可以解释一下吗:
var str = "↵Since we are starting our webservice..."; alert(str.charAt(0)) alert(str.charCodeAt(0)); alert(/\u8629/.test("↵"));
http://jsfiddle.net/SXYAn/1/
字符串对象方法告诉我“↵”的 unicode 代码是 8629,但 RegExp 说情况并非如此。
您将 charCode 作为十进制数返回,并且在 regEx 中进行测试时,您需要使用 HEX 数。
8629=0x21b5。
我用这个来弄清楚。