I am reading a txt file with StreamReader and it appears to be outputting escape characters. I am using the following code:
using (StreamReader reader = new StreamReader(saveLocation, System.Text.Encoding.UTF8))
{
string line;
while ((line = reader.ReadLine()) != null)
{
...
}
}
When I open the txt file manually the line in question reads value_start "FILE_NAME"
, but the line
value in Visual Studio that gets saved to my data structure is " value_start "FILE_NAME""
. I believe the escape characters are being included, but in my research on this topic StreamReader should ignore escape characters.
My file is being written like so:
private static void WriteIndexFile(
string saveLocation,
SortedDictionary<string, string> filesToWrite)
{
using (StreamWriter writer = new StreamWriter(saveLocation, false, System.Text.Encoding.UTF8))
{
writer.WriteLine("cross_ref");
foreach (KeyValuePair<string, string> kvp in filesToWrite)
{
writer.WriteLine($" file_start "{kvp.Key}"");
writer.WriteLine($" filename "{kvp.Value}"");
writer.WriteLine($" #modified {File.GetLastWriteTime(kvp.Value).ToString()}");
writer.WriteLine($" file_end");
}
writer.WriteLine("end_cross_ref");
}
}
Is there anything I’m doing wrong when writing or reading my files that would be causing the escape characters to be read?