-5

I have this String

link="https%3a%2f%2fen.wikipedia.org%2fwiki%2fHuawei/"

which shoud be like this:

link="https://en.wikipedia.org/wiki/Huawei/"

I wrote this code:

link.Replace("%2f", "/");
link.Replace("%3a", ":");

But it did not work.

mary
  • 247
  • 3
  • 20

3 Answers3

3

Instead of trying to decode the URL yourself I'd use HttpUtility.UrlDecode

HttpUtility.UrlDecode("https%3a%2f%2fen.wikipedia.org%2fwiki%2fHuawei/")
"https://en.wikipedia.org/wiki/Huawei/"

See: https://msdn.microsoft.com/en-us/library/system.web.httputility.urldecode(v=vs.110).aspx

hardkoded
  • 18,915
  • 3
  • 52
  • 64
1

String.Replace does return the value replaced try:

link = link.Replace("%2f", "/");
Cleptus
  • 3,446
  • 4
  • 28
  • 34
0

link is a string and is not mutating when you call the Replace method

link.Replace will not affect the link object itself, instead it returns a new String from the doc emphasis mine:

Returns a new string in which all occurrences of a specified Unicode character in this instance are replaced with another specified Unicode character.

do instead:

link = link.Replace("%2f", "/");   or
link = link.Replace("%3a", ":");
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97