我已经尝试过使用WebUtility.UrlEncode和Uri.UnescapeDataString,但它正在编码整个网址,但我只想填补%20的空白(空格)。我的代码如下。
string url = "https://www.example.com/images/catalog/operators/Ajmer Vidyut Vitran Nigam.png";
//Method1
string imageUrl = WebUtility.UrlEncode(url);
//Method2
string temp = Uri.EscapeDataString(url);
编码后的实际网址:" https%3A%2F%2Fassetscdn.paytm.com%2Fimages%2Fcatalog%2Foperators%2FAjmer + Vidyut + Vitran + Nigam.png"
预期网址: " https://assetscdn.paytm.com/images/catalog/operators/Ajmer%20Vidyut%20Vitran%20Nigam.png"
提前致谢:)
答案 0 :(得分:1)
string imageUrl = Uri.EscapeUriString(url);
答案 1 :(得分:0)
您可以使用HttpUtility.UrlPathEncode方法(String)。查看更多信息here