Search code examples
c#c#-4.0text

How to produce a soft return using C#.net


I know this is kind of easy question but i cant seem to find it anywhere. Is there someone out there who knows how to create a soft return inside a set of text using C#.net?

I need to print soft return to a text file/xml file. this text file will be generated using c#.net. you could verify if the answer is correct if you use NOTEPAD++ then enable the option to “View>Show Symbol > Show End of Line” then you will see a symbol like this:

enter image description here

Thanks in advance :)


Solution

  • Not sure what you mean by a soft return. A quick Google search says it's a non-stored line break typically due to word wrapping in which case you wouldn't actually put this in a string, it would only be relevant when the string was rendered for display.

    To put a carriage return and/or line feed in the string you would use:

    string s = "line one\r\nline two";
    

    And for further reference, here are the other escape codes that you can use.

    Link (MSDN Blogs)

    In response to your edit

    The LF that you see can be represented with \n in a string. Obviously you have a specific line ending sequence that you need to represent. If you were to use Environment.NewLine that is going to give you different results on different platforms.