CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2002
    Location
    ireland
    Posts
    291

    Normalize line endings, how?

    I'm working with Visual studio, I'm writing to a file, when I open the file in Visual Studio's text editor I get the following error:

    "The line endings in the following file are not consistent. Do you want to normalize the line endings?"

    How can I normalize the line endings from code before displaying the file?

    Visual Studios error prompts you to normalize, I've compared a normalized and un-normalized file, the only difference I see is the File Type is different in the files properties, the normalized files type is "PC" the un-normalized in "Unknown", is this a clue?

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Normalize line endings, how?

    It seems like when you write your file you sometimes use PC end-of-line CR/LF and sometimes unix end-of-line that is only a LF.

    Edit: Should have mentioned. The proper way to add a newline character is by using Environment.NewLine. I.e. String myStr = "Some text" + Environment.NewLine;
    Last edited by S_M_A; June 1st, 2007 at 03:38 AM.

  3. #3
    Join Date
    Aug 2002
    Location
    ireland
    Posts
    291

    Re: Normalize line endings, how?

    SMA,
    You are bang on, I just came across it in the msdn docs and then tried it before you're response and it'sexactly what the problem was.
    Environment.NewLine instead of \n is the solution.
    Lovely jubely.

  4. #4
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Normalize line endings, how?

    Nice to hear!

  5. #5
    Join Date
    Nov 2008
    Posts
    6

    Re: Normalize line endings, how?

    Hi Guys,

    I have the same problem but not sure what you mean by Environment.NewLine???? Where do I do this and how?

    Many thanks

  6. #6
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Normalize line endings, how?

    Quote Originally Posted by S_M_A View Post
    Edit: Should have mentioned. The proper way to add a newline character is by using Environment.NewLine. I.e. String myStr = "Some text" + Environment.NewLine;
    Of course if you are using a "WriteLine" method, then this is done implicitly, and you do NOT add a newline (in any form) to the data itself....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  7. #7
    Join Date
    Aug 2002
    Location
    ireland
    Posts
    291

    Re: Normalize line endings, how?

    Quote Originally Posted by Mona777 View Post
    Hi Guys,

    I have the same problem but not sure what you mean by Environment.NewLine???? Where do I do this and how?

    Many thanks
    http://msdn.microsoft.com/en-us/libr...t.newline.aspx

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

Featured