从Server.UrlEncode获取字符串为大写 [英] Get string from Server.UrlEncode as uppercase

查看:215
本文介绍了从Server.UrlEncode获取字符串为大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望它的输出为大写。这是我在 Server.UrlEncode(http://)

  http%3a%2f%2f 

但我需要:

  http%3A%2F%2F 

C#中是否有内置解决方案?






编码的URL将作为签名基础字符串输入到签名算法)来创建摘要(哈希)。
然后哈希将被其他系统(java,php等)验证,所以他们需要首先通过签名重建来重新创建哈希。

解决方案

这将使您的字符串中的所有转义字符大写

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


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.

解决方案

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

这篇关于从Server.UrlEncode获取字符串为大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆