views:

428

answers:

2

What I have is a txt file that is huge, 60MB. I need to read each line and produce a file, split based on a delimiter. I'm having no issue reading the file or producing the file, my complication comes from the delimiter, it can't see the delimiter. If anybody could offer a suggestion on how to read that delimiter I would be so grateful.

delimiter = Ç

public void file1()
    {
        string betaFilePath = @"C:\dtable.txt";
        StringBuilder sb = new StringBuilder();
        using (FileStream fs = new FileStream(betaFilePath, FileMode.Open))
        using (StreamReader rdr = new StreamReader(fs))
        {
            while (!rdr.EndOfStream)
            {
                string[] betaFileLine = rdr.ReadLine().Split('Ç');
                {
                    sb.AppendLine(betaFileLine[0] + "ç" + betaFileLine[1] + betaFileLine[2] + "ç" + betaFileLine[3] + "ç" + betaFileLine[4] + "ç" + betaFileLine[5] + "ç" + betaFileLine[6] + "ç" + betaFileLine[7] + "ç" + betaFileLine[8] + "ç" + betaFileLine[9] + "ç" + betaFileLine[10] + "ç");
                }
            }
        }
        using (FileStream fs = new FileStream(@"C:\testarea\load1.txt", FileMode.Create))
        using (StreamWriter writer = new StreamWriter(fs))
        {
            writer.Write(sb.ToString());
        }
    }

Small update:

string[] betaFileLine = rdr.ReadLine().Split('Ç');

It's not able to split on the charecter Ç. When i debug it, it comes out to be an unreadable charecter.

Guys, thanks for the help you defiently pointed my in the right direction. Changing:
using (StreamReader rdr = new StreamReader(fs))
To:
using (StreamReader rdr = new StreamReader((fs),Encoding.Default))

Fixed it. Thank you!

+3  A: 

Make sure your StreamReader uses the same text encoding as your text file. The constructor can take a second parameter to indicate the encoding to use.

David M
Thats the thing, it see's the line just fine, it doesnt seem the delimiter.
Mike
I'e tried changing it to using (StreamReader rdr = new StreamReader((fs),Encoding.ASCII)) but this just results in the Ç being read as a ?
Mike
+2  A: 

It looks like you are splitting on Ç but adding ç. Not something as simple as replacing the uppercase delimiter with the lowercase or vice versa.

Ardman
Doesnt get past the line split.
Mike
Does the dtable.txt file contain the Ç character?
Ardman
Yeah, i actually just found a fix, see my edit!
Mike