encoding problem

hi,

I'm working on application that retrieves emails from POP mail account,

The probleme is this:

If have a message with special caracteres like "e e a", all what I get after retrieving the message is " " in the place of these caracters.

The message was encoded with "ISO-8895-1"

Check this code:
//sTemp has a ligne of the message
Encoding srcEnc = Encoding.ASCII;
byte[] srcData = srcEnc.GetBytes(sTemp); //the source data turned to byte array
Encoding dstEnc = Encoding.GetEncoding("iso-8859-1");
byte[] dstData = Encoding.Convert(srcEnc, dstEnc, srcData);
sTemp = dstEnc.GetString(dstData);

the final result is the same whitout this code, all caracteres (e e a) turns to " " .

When I check srcData.Equals(dstData) it gives me a false message, which means that the two buffer are diffirent.

hope you help me.


Answer this question

encoding problem

  • Simon Morris

    The problem is with srcEnc.GetBytes(sTemp);

    You're telling the framework to convert a Unicode string to bytes using ASCII encoding. Only the Unicode characters that overlap in ASCII will be encoded; all others will be replaced with ' '. Try this instead:


    byte[] srcData = Encoding.Unicode.GetBytes(sTemp);
    byte[] dstData = Encoding.Convert(Encoding.Unicode,
    Encoding.GetEncoding("iso-8859-1"), srcData);



  • encoding problem