Reputation: 396
I am trying to use the HttpUtility.HtmlEncode to encode an underscore to %5f, but the encoded value does not give me the hex representation. How will I accomplish this?
string encodedValue = HttpUtility.HtmlEncode("First_Name");
The value I want in the encodedValue string is "First%5FName".
Is there something I am missing? I have also tried using the HttpUtility.UrlEncode, but that does not give me the desired result as well.
I know this should be something simple, but I cant get around it.
Upvotes: 5
Views: 31349
Reputation: 121
It's an old subject but to convert a char in its HexEscape format you should use:
myString.Replace("_", Uri.HexEscape("_"));
Upvotes: 2
Reputation: 655
if you just want to replace _
with %5f
, you can just use myString.Replace("_", "%5f");
Upvotes: 12