Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get string from Server.UrlEncode as uppercase

I want its output as uppercase. This is what I get on Server.UrlEncode("http://"):

http%3a%2f%2f

but I need:

http%3A%2F%2F

Is there built-in solution in C#?


The url encoded shall serve as signature base string (input to signature algorithm) to create digest (hash). The hash will then be verified by other system (java,php,etc), so they need to recreate the hash by signature reconstruction first.

like image 886
lax Avatar asked Jun 16 '11 11:06

lax


2 Answers

This will uppercase all escaped characters in your string.

string url = "http://whatever.com/something";
string lower = Server.UrlEncode(url);
Regex reg = new Regex(@"%[a-f0-9]{2}");
string upper = reg.Replace(lower, m => m.Value.ToUpperInvariant());
like image 152
agent-j Avatar answered Nov 18 '22 13:11

agent-j


Uri.EscapeDataString("http://")

This code return

http%3A%2F%2F
like image 23
PlushEngineCell Avatar answered Nov 18 '22 13:11

PlushEngineCell