469,269 Members | 1,006 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,269 developers. It's quick & easy.

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?
Feb 16 '08 #1
1 7580
I have resolved this problem.

The default character set encoding that StreamWriter uses is not ISO 8599-1 (WesternEuropean) 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 isoWesternEuropean = Encoding.GetEncoding(28591);
StreamReader htmFile = new StreamReader(HTM_FILE_PATH + fileName + ".htm", isoWesternEuropean);
StreamWriter tmpFile = new StreamWriter(HTM_FILE_PATH + "temp.php", APPEND, isoWesternEuropean);

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.
Feb 21 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by ASP Yaboh | last post: by
9 posts views Thread by ShadowOfTheBeast | last post: by
3 posts views Thread by Mads Westen | last post: by
7 posts views Thread by Eran.Yasso | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.