C# StreamWriter.WriteLine replacing A0 with EF BF BD

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mbluett
    New Member
    • Feb 2008
    • 2

    C# StreamWriter.WriteLine replacing A0 with EF BF BD

    I am having a problem with a C# application that I wrote sometime ago. It worked fine after creating it and for roughly a year after. At some point within 2007 something changed on my Windows XP system whereby this application started to replace any hex A0 with hex EF BF BD.

    The application is written using .net 2.0 and was created using C# VS2005 Express.

    I have since recompiled it with .NET 3.5 and C# VS 2008 Express installed with no resolution to the problem.

    I have tried all of the Encoding parameters to the StreamWriter class, but they all produce the same problem with the exception of ASCII which converts A0 to CF (if I remember correctly).

    The file that my C# app is re-writing is an HTML file with ISO 8859-1 encoding. The hex A0 is &nbsp (in html). I wish the A0 to be left as in the original html file.

    Any ideas on how to resolve this issue?
  • mbluett
    New Member
    • Feb 2008
    • 2

    #2
    I have resolved this problem.

    The default character set encoding that StreamWriter uses is not ISO 8599-1 (WesternEuropea n) and needs to be when processing a file that has been encoded with ISO 8599-1 (such as is the case with some webpages).

    Problem resolution:

    Encoding isoWesternEurop ean = Encoding.GetEnc oding(28591);
    StreamReader htmFile = new StreamReader(HT M_FILE_PATH + fileName + ".htm", isoWesternEurop ean);
    StreamWriter tmpFile = new StreamWriter(HT M_FILE_PATH + "temp.php", APPEND, isoWesternEurop ean);

    To find all the .NET supported character sets, look at the MSDN documentation in the Encoding class. This shows that "28591" is the .NET reference for ISO 8859-1.

    Comment

    Working...