views:

30

answers:

1

I have a logfile that contains the half character ½, I need to process this log file and rewrite certain lines to a new file, which contain that character. However, when I write out the file the characters appear in notepad incorrectly.

I know this is some kind of encoding issue, and i'm not sure if it's just that the files i'm writing don't contain the correct bom or what.

I've tried reading and writing the file with all the available encoding options in the Encoding enumeration.

I'm using this code:

string line;

// Note i've used every version of the Encoding enumeration
using (StreamReader sr = new StreamReader(file, Encoding.Unicode))
using (StreamWRiter sw = new StreamWriter(newfile, false, Encoding.Unicode))
{
    while ((line = sr.ReadLine()) != null)
    {
        // process code, I do not alter the lines, they are copied verbatim
        // but i do not write every line that i read.

        sw.WriteLine(line);
    } 
}

When I view the original log in notepad, the half character displays correctly. When I view the new file, it does not. This tells me the problem is not with notepad being able to display the character, because it works in the original.

Can anyone help me to solve this?

A: 

The solution was PEBKAC.

I was changing the encodings in a different part of the program that wasn't creating these files. When I changed the correct files, using Encoding.Default, it displays correctly.

Thanks Jon and others.

Mystere Man