简体   繁体   中英

String.Replace for “\”

I can't seem to get this to work. My cookie's string value has a leading and ending "\\" in it.

Example cookie value would be:

"\"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 "\\".

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 \\.

Is it that the \\ you're seeing is really just the escape char on the " character?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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