1

I've tried to use HttpUtility.UrlEncode in order to simulate the javscript's encodeURIComponent, but had some issues (instead of getting "%20" i got "+")

then I've replaced the string, but i see that the problem is not only in these two signs, in some places the encoded string (by UrlEncode) is totally different from the encoded string by using encodeURIComponent.

Any ideas how it can be solved ?

thanks.

Igal
  • 4,603
  • 14
  • 41
  • 66
  • 3
    Possible duplicate: http://stackoverflow.com/questions/86477/does-c-have-an-equivalent-to-javascripts-encodeuricomponent – as-cii Sep 25 '11 at 13:01
  • it's not a duplicate, as i said, my problem is not in "+" or "%20%" but in wrong encoding... when i use c# encoder, i get different chars than the encodeURIComponent encoding... – Igal Sep 25 '11 at 13:18
  • 2
    What if you try `Uri.EscapeUriString("some uri...")`? – as-cii Sep 25 '11 at 20:52
  • 1
    Possible duplicate of [Does C# have an equivalent to JavaScript's encodeURIComponent()?](https://stackoverflow.com/questions/86477/does-c-sharp-have-an-equivalent-to-javascripts-encodeuricomponent) – Adrian Sep 19 '18 at 04:04

1 Answers1

1

You are looking for HttpUtility.UrlPathEncode.

See this SO question: Server.UrlEncode vs. HttpUtility.UrlEncode

Community
  • 1
  • 1
Joel Peltonen
  • 13,025
  • 6
  • 64
  • 100
  • Shouldn't that have been a comment instead, linking to post that has an answer? – Nikhil Vartak May 12 '17 at 03:26
  • @niksofteng In that case this question could not be closed. I was hoping that OP would accept this so that this question could be concidered as answered and it would work with the question tag statistics. I'm not sure how they work now but back in '13 this for example would have been counted as an "Unanswered" question when browsing through tags. Even though it would have been answered in comments. Also, Google users don't read comments. I don't even read comments. TL;DR: Answer from comments is better than question without answers but solution in comments. – Joel Peltonen May 15 '17 at 09:41
  • I hope @Igal reads this and closes the question at least now. – Nikhil Vartak May 15 '17 at 11:11