简体   繁体   English

如何在C#中将文字字符串转换为普通字符串

[英]How to convert literal string to normal string in c#

For example: mystr="\\"http:\\\\/\\\\/somedomain.com\\""; 例如: mystr="\\"http:\\\\/\\\\/somedomain.com\\"";

i want to convert this string to "http://somedomain.com"; 我想将此字符串转换为"http://somedomain.com";

HttpUtility.HtmlDecode and HttpUtility.UrlDecode dont work HttpUtility.HtmlDecodeHttpUtility.UrlDecode不起作用

how can convert this? 如何转换呢?

This is because you need to escape the "\\" and the quotes (") character in C#. There is no Encoding / Decoding to do. If you want to get rid of the confusing backslashes add a @ before your string 这是因为您需要在C#中转义“ \\”和引号(“)字符。无需进行编码/解码。如果要摆脱混乱的反斜杠,请在字符串前添加@

myStr = @"http://www.google.com" myStr = @“ http://www.google.com”

Nevertheless, your string looks weird so you will need to get the text inside the quotes and then remove those weirdly placed "\\" in the http:// part. 但是,您的字符串看起来很怪异,因此您需要将文本放在引号中,然后删除那些在http://部分中怪异放置的“ \\”。

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

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