gpt4 book ai didi

c# - 对非转义字符有什么作用?

转载 作者:数据小太阳 更新时间:2023-10-29 06:13:37 25 4
gpt4 key购买 nike

asked another question poorly所以我会问别的问题。

根据 http://www.c-point.com/javascript_tutorial/special_characters.htm有一些转义字符,例如\n 和\b。但是/不是其中之一。在这种情况下会发生什么? (\/) 是否忽略了 \

我在 javascript 'http:\/\/www.site.com\/user' 中有一个字符串。并不是说这是一个带有 ' 的文字,所以对于 " 它看起来像 \\/ 无论如何我想转义这个字符串因此问题关于非“特殊”转义字符会发生什么。

另一个问题是,如果我有 name:\t me(或 "name:\\t me" 是否有一个函数来转义它,所以有一个选项卡?我正在使用 C#,这些字符串来自 JSON 文件

最佳答案

根据 Mozilla 的说法:

For characters not listed [...] a preceding backslash is ignored, but this usage is deprecated and should be avoided.

https://developer.mozilla.org/en/JavaScript/Guide/Values%2c_Variables%2c_and_Literals#section_19

\/ 序列未列出,但至少有两种常见用法:

<1> 需要在使用 /foo/ 语法的正则表达式中转义文字斜杠:

var re = /^http:\/\//;

<2> 在 HTML 中嵌入 JavaScript 代码时,需要避免无效的 HTML:

<script type="text/javascript"><!--
alert('</p>')
//--></script>

... 触发器:未打开的元素“P”的结束标记

<script type="text/javascript"><!--
alert('<\/p>')
//--></script>

...没有。

关于c# - 对非转义字符有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4396544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com