Underscore encoding to% 5F

I am trying to use HttpUtility.HtmlEncode to encode the underscore in% 5f, but the encoded value does not give me a hexadecimal representation. How do i do this?

string encodedValue = HttpUtility.HtmlEncode("First_Name"); 

The value I want in the encodedValue line is "First% 5FName".

Is there something I am missing? I also tried using HttpUtility.UrlEncode, but that also does not give me the desired result.

I know that this should be something simple, but I cannot get around it.

+4
source share
2 answers

if you just want to replace _ with %5f , you can just use myString.Replace("_", "%5f");

+9
source

This is an old object, but to convert char to its HexEscape format, you should use:

 myString.Replace("_", Uri.HexEscape("_")); 
0
source

All Articles