Results 1 to 3 of 3

Thread: [RESOLVED] [1.0/1.1] Appending tabs and line breaks to a text file.

  1. #1

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Resolved [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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: [1.0/1.1] Appending tabs and line breaks to a text file.

    Thanks, i saw my error!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width