[RESOLVED] [1.0/1.1] Appending tabs and line breaks to a text file.
Hi guys. I know how to create a text file and append text to that text file. But does anyone know how to insert tabs or newlines to a text file? I'm using the backslash character \ but it's still not recognizing it.
if (!File.Exists(@"test.txt"))
{
using (StreamWriter sw = File.CreateText(@"test.txt"))
{
sw.WriteLine("Start text\tHello\nhi\n");
}
}
I want this:
Start text Hello
hi
but i'm getting this: Start text\tHello\nhi\n
jennifer
Re: [1.0/1.1] Appending tabs and line breaks to a text file.
Are you sure that you've used this:
Code:
sw.WriteLine("Start text\tHello\nhi\n");
and not this:
Code:
sw.WriteLine(@"Start text\tHello\nhi\n");
The fact that you've used the "@" in two other places where it was not needed suggests that perhaps you don't know exactly what it's for. If you prefix a string literal with the verbatim character like that then all escape characters are taken literally. You normally use it on file paths so that you don't have to double up all the back slashes. Using it on strings with no escape characters is pointless and using it on strings in which you want escape characters is not possible.
Re: [1.0/1.1] Appending tabs and line breaks to a text file.