且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Javascript用单反斜杠替换双反斜杠

更新时间:2022-12-11 08:06:57

JavaScript 字符串需要转义 所以如果你得到一个带有两个反斜杠的字符串文字,JavaScript 会将它解释为一个.在您用来比较的字符串中,您有 \t,它是一个制表符,而您可能想要的是 \\t.我的猜测是,无论您从何处获取当前 SharePoint 用户,它都会被正确转义,但您的比较列表却不是.

JavaScript strings need to be escaped so if you are getting a string literal with two back slashes, JavaScript interprets it as just one. In your string you are using to compare, you have \t, which is a tab character, when what you probably want is \\t. My guess is that wherever you are getting the current SharePoint user from, it is being properly escaped, but your compare list isn't.

或者反过来.如果您使用 .NET 4+ JavaScriptStringEncode 可能会有所帮助.如果您仍然遇到问题,向我们展示您是如何进行比较可能会有所帮助.

Or maybe the other way around. If you're using .NET 4+ JavaScriptStringEncode might be helpful. If you're still having problems it might help to show us how you are doing the comparison.