Uppercase url encoding
Possible duplicate:
.net UrlEncode - lower case problem
I am using the HttpUtility.UrlEncode method to encode the string for me. The problem is that the letters in the encoded places are lowercase, for example:
the colon (:) becomes% 3a, not% 3A.
Not much of a problem until I come to encrypt this string. The end result I want is as follows.
zRvo7cHxTHCyqc66cRT7AD%2BOJII%3D
If I use capital letters I get this
zRvo7cHxTHCyqc66cRT7AD+OJII=
which is correct, but if I use lowercase letters (i.e. use UrlEncode and not a static string) I get this
b6qk+x9zpFaUD6GZFe7o1PnqXlM=
This is obviously not the line I want. Is there an easy way to make capital of the encoded characters without reusing the UrlEncoding wheel?
Thnaks
source to share
Of course, the CAP string before encoding it. Encoding is generally a one-way street based on literal character values, so it should come as no surprise that this is different. I'm really wondering what type of value are you using for this? There is definitely a better way to deal with the type of data you are encoding.
Adding a linked duplicate:
public static string UpperCaseUrlEncode(this string s)
{
char[] temp = HttpUtility.UrlEncode(s).ToCharArray();
for (int i = 0; i < temp.Length - 2; i++)
{
if (temp[i] == '%')
{
temp[i + 1] = char.ToUpper(temp[i + 1]);
temp[i + 2] = char.ToUpper(temp[i + 2]);
}
}
return new string(temp);
}
Including it in an extension method allows any string variable to encode the UPPER CASE url.
source to share