UrlEncode French characters - wrong encoding

  • Thread starter Thread starter John C.
  • Start date Start date
J

John C.

Hi, I've tried using System.Web.HttpUtility.UrlEncode("é") with each
of the possible encodings ASCII, Unicode, UTF7, UTF8 but none of these
gives what I want: %e9. And so on for the other French characters. Am I
missing something here?
 
John said:
Hi, I've tried using System.Web.HttpUtility.UrlEncode("é") with each
of the possible encodings ASCII, Unicode, UTF7, UTF8 but none of these
gives what I want: %e9. And so on for the other French characters. Am I
missing something here?

Use ISO-8859-1 as the encoding name. Or Windows-1252. e.g.
HttpUtility.UrlEncode("é",
System.Text.Encoding.GetEncoding("ISO-8859-1"))
 
Thus wrote John C.,
Hi, I've tried using System.Web.HttpUtility.UrlEncode("é") with each
of the possible encodings ASCII, Unicode, UTF7, UTF8 but none of these
gives what I want: %e9. And so on for the other French characters. Am
I missing something here?

Yes, the correct encoding ;-)

ISO-8859-15 or Windows-1252 is the encoding you're probably looking for:

Encoding latin9 = Encoding.GetEncoding("iso-8859-15");
string encodedUrl = HttpUtility.UrlEncode(url, latin9);

Cheers,
 
Thus wrote Martin,
Use ISO-8859-1 as the encoding name. Or Windows-1252. e.g.
HttpUtility.UrlEncode("é",
System.Text.Encoding.GetEncoding("ISO-8859-1"))

Some fun encoding trivia: There are two french glyphs that don't exist in
ISO-8859-1: The uppercase and lowercase "oe" ligature (Unicode \u0152 and
\u0153). That's why I've proposed Latin 9 instead in my other post. If it's
all about "é", Latin 1 is OK :-)

Cheers,
 
Off topic ;-)

Martin Honnen wrote:

Martin, you're the Martin Honnen who was (and maybe still is, I lost
contact lately) on comp.lang.javascript, I suppose. Nice to see you here
too.

Friendly greetings,
Laurent
 
Back
Top