Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, July 16, 2009 4:28 PM
I am receiving a text file that when viewed looks like it has blank lines when in reality the ReadLine() method returns a long string of "\0\0\0......". I am trying to explore this file and get rid of these lines. The Code is provided but it doesn't get rid of the \0's . I have also tried Replace(\0,"") and Replace(" ", "").
using (StreamReader reader = new StreamReader("C:\CSharp\Test\Deploy\"+filename+".txt"))
{
string linedata;
while ((linedata = reader.ReadLine()) != null)
{
linedata = linedata.Trim();
//Get rid of blank chars???
linedata.Replace(
"\0", "");
if (linedata.Length > 0)
{
datastrings.Add(linedata);
}
}
}
All replies (2)
Thursday, July 16, 2009 4:29 PM âś…Answered
You're not reassigning lineData. Remember, strings are immutable:
You have:
lineData.Replace("\0", "");
Should be:
lineData = lineData.Replace("\0", "");
David Morton - http://blog.davemorton.net/ - @davidmmorton - ForumsBrowser, a WPF MSDN Forums Client
Thursday, July 16, 2009 6:09 PM
Thanks. It is always something small!