QUOTE(davegeek @ 26 Mar, 2008 - 05:15 PM)

But the thing is that u are using some sort of regular expression with the split method.
Can we do it simply by using some less complex code like the one that i wrote initially?
But, but, I like regular expressions...

You're basically there, actually. The real trick lies in the [li]s.Replace("\r", "")[/li]. By just getting rid of the offending character, the code get's very simple.
By splitting out the lines, you just have to process each line by itself, with a writeline at the end.
Adjusted code would look like so:
csharp
void CommaMe(string s, TextWriter writer) {
foreach (string line in s.Replace("\r", "").Split('\n')) {
for(int i=0; i<line.Length; i++) {
if (i>0) { writer.Write(","); }
writer.Write(line[i]);
}
writer.WriteLine();
}
}
With a call like so:
csharp
TextReader reader = new StreamReader("c:/FileLogs/Log.txt");
string a = reader.ReadToEnd();
reader.Close();
FileStream aFile = new FileStream("c:/FileLogs/Log.csv", FileMode.OpenOrCreate);
CommaMe(a, new StreamWriter(aFile));
aFile.Close();