The reason is not that .NET uses UTF-16 encoded strings. The reason is that the UrlEncode(string)
overload uses UTF-8 by default, and %C3%A2
is the correct UTF-8 encoding of â
:
The HttpUtility.UrlEncode method uses UTF-8 encoding by default. Therefore, using the UrlEncode method provides the same results as using the UrlEncode method and specifying UTF8 as the second parameter.
If you prefer a different encoding (for example Latin-1 or Codepage 1252, where â
corresponds to %E2
), you can use another overload that allows you to specify an encoding:
var x = HttpUtility.UrlEncode("â", Encoding.GetEncoding(1252));