Get string from Server.UrlEncode as uppercase

狂风中的少年 提交于 2019-12-14 04:16:41

问题


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.


回答1:


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());



回答2:


Uri.EscapeDataString("http://")

This code return

http%3A%2F%2F



回答3:


This is very easy

Regex.Replace( encodedString, @"%[a-f\d]{2}", m => m.Value.ToUpper() )

I.e. replace all hex letter-digit combinations to upper case




回答4:


Assuming "http" is always the first four characters then you simply split the string after "http", UrlEncode that part and then call ToUpper() on it. Then join back together with "http" as your prefix.



来源:https://stackoverflow.com/questions/6371086/get-string-from-server-urlencode-as-uppercase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!