UrlEncode French characters - wrong encoding

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?
 
M

Martin Honnen

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"))
 
J

Joerg Jooss

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,
 
J

Joerg Jooss

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,
 
L

Laurent Bugnion

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top