Get string from Server.UrlEncode as uppercase

前端 未结 5 1200
忘掉有多难
忘掉有多难 2021-01-08 00:35

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

http%3a%2f%2f

but I need:

<         


        
相关标签:
5条回答
  • 2021-01-08 00:59

    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

    0 讨论(0)
  • 2021-01-08 01:04
    Uri.EscapeDataString("http://")
    

    This code return

    http%3A%2F%2F
    
    0 讨论(0)
  • 2021-01-08 01:05

    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.

    0 讨论(0)
  • 2021-01-08 01:07

    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());
    
    0 讨论(0)
  • 2021-01-08 01:07

    I encountered the same problem, I found the answer in this link:

    WebUtility.UrlEncode or HttpUtility.UrlEncode

    in-short you can use:

    System.Net.WebUtility.UrlEncode
    

    which encodes into uppercase hex values

    0 讨论(0)
提交回复
热议问题