防止反斜杠被 javascript 解析为字符串
Flash AS3 IRC 应用程序将“f\reak”之类的字符串传递给 JavaScript。 IRC 允许在用户名中使用 \,这在传递给 JavaScript 时会产生问题。
"f\reak" 在 JavaScript 中变成 "feak",使 \r 变成回车符。
有没有办法读取字符串的绝对值而不是解析回车符?
这些方法不起作用
str.valueOf()
str.toString()
str.charAt(\ 的位置) 这也只看到回车符而不是反斜杠
A Flash AS3 IRC application passes me a string like "f\reak" to JavaScript. IRC allows the \ in usernames which poses a problem when its passed to JavaScript.
"f\reak" become "feak" in javascript making the \r into a carriage return.
Is there a way to read the absolute value of the string instead of parsing a carriage return?
These methods didn't work
str.valueOf()
str.toString()
str.charAt(position of the \ ) this just sees the carriage return as well and not a backslash
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尽管这看起来不是最佳方法,但我可以向您推荐一件事。所以,首先你需要知道javascript中的所有转义序列。您可以在此处获取这些内容。现在,由于它们的数量不是太多,您可以在提供的字符串中单独检查每个转义序列是否存在。为此,您可以使用
类似的方法,您也必须对其他转义序列执行此操作。因此,无论如何,对于任何字符串,您至少都会知道是否有转义序列,如果是,您可以根据您的要求处理该字符串。
Though it doesn't seem a optimal way, I can recommend you one thing. So, first of all you need to know all the escape sequences in javascript. You can get those here. Now as there are not too many of them, you can check the presence of each of the escape sequences individually in the provided string. To do this you can use
Similarly you have to do for other escape sequences. So, nevertheless of any string you will at least know whether any escape sequences are there are not and if yes you can handle that string as per your requirement.