简体   繁体   English

字符串。替换为“ \\”

[英]String.Replace for “\”

I can't seem to get this to work. 我似乎无法使它正常工作。 My cookie's string value has a leading and ending "\\" in it. 我的Cookie的字符串值的开头和结尾均带有“ \\”。

Example cookie value would be: Cookie值示例如下:

"\"access_token=106447086076952%7C2.6l1KfdJFyvOgYuxgxn7__A__.3600.1282712400-1637262814%7CwUkJfvzS1CVSlg8H-DXOg94WlTA.&expires=1282712400&secret=y6LY_I_20sykbhU90hQKrg__&session_key=2.6l1KfdJFyvOgYuxgxn7__A__.3600.1282712400-1637262814&sig=6a62b60bb78fc51af"\"

I have no idea where this "\\" is coming from but it's causing me all sorts of hell here and I need to get rid of it so that the HttpValueCollection doesn't get all screwed up with the "\\". 我不知道这个“ \\”是从哪里来的,但是这使我陷入各种困境,我需要摆脱它,以便HttpValueCollection不会被“ \\”搞砸。

I tried this with no luck, the value still shows "\\": 我没有运气尝试过,该值仍然显示“ \\”:

facebookAuthCookie.Value = facebookAuthCookie.Value.Replace(@"\", string.Empty);

also tried 也尝试过

facebookAuthCookie.Value = facebookAuthCookie.Value.Replace("\\", string.Empty);

As you've presented it, it looks more like you have an escaped double quote in the string rather than a slash. 正如您所介绍的那样,它看起来更像是字符串中的转义双引号而不是斜杠。 So you probably want: 因此,您可能想要:

facebookAuthCookie.Value = facebookAuthCookie.Value.Replace("\"", string.Empty);

I'm interpreting that cookie string as having a " at its start and end, not \\. 我将Cookie字符串解释为在其开头和结尾都带有“,而不是\\。

Is it that the \\ you're seeing is really just the escape char on the " character? 您看到的\\真的只是字符上的转义字符吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM