Basic question . . .

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lauchlan M

    #1

    Basic question . . .

    How do I add a linefeed (ASCII character 10) to a string?

    For example in Delphi I would do

    TheString := PreString+ Chr(10) + PostString;

    Where Chr(10) whacks in the ascii character for line feed / carriage return
    and prestring and poststring are other strings.

    How do I do this in C#?

    Thanks!

    Lauchlan M


  • Carl Fenley

    #2
    Re: Basic question . . .

    It depends...

    If you simply want to throw a carriage-return linefeed into a string for
    display, simply use the \n code. For example:

    string strTest = "This is the First Line.\nThis is the Second Line."

    If you're writing to a file, you may find the NewLine property of the
    TextWriter convenient.

    - Carl

    "Lauchlan M" <LMackinnon@Hot mail.com> wrote in message
    news:eYlfMhbeDH A.2436@TK2MSFTN GP11.phx.gbl...[color=blue]
    > How do I add a linefeed (ASCII character 10) to a string?
    >
    > For example in Delphi I would do
    >
    > TheString := PreString+ Chr(10) + PostString;
    >
    > Where Chr(10) whacks in the ascii character for line feed / carriage[/color]
    return[color=blue]
    > and prestring and poststring are other strings.
    >
    > How do I do this in C#?
    >
    > Thanks!
    >
    > Lauchlan M
    >
    >[/color]


    Comment

    • Greg Ewing [MVP]

      #3
      Re: Basic question . . .

      Also, if you would like to write platform independent code, use
      Environment.New Line instead.

      --
      Greg Ewing [MVP]
      IT support built exclusively for nonprofits. 25 years of managed IT, help desk, and cybersecurity - so your team can focus on your mission.


      "Carl Fenley" <cfenley1-X-@-X-san.rr.com> wrote in message
      news:uVCndubeDH A.1836@TK2MSFTN GP09.phx.gbl...[color=blue]
      > It depends...
      >
      > If you simply want to throw a carriage-return linefeed into a string for
      > display, simply use the \n code. For example:
      >
      > string strTest = "This is the First Line.\nThis is the Second Line."
      >
      > If you're writing to a file, you may find the NewLine property of the
      > TextWriter convenient.
      >
      > - Carl
      >
      > "Lauchlan M" <LMackinnon@Hot mail.com> wrote in message
      > news:eYlfMhbeDH A.2436@TK2MSFTN GP11.phx.gbl...[color=green]
      > > How do I add a linefeed (ASCII character 10) to a string?
      > >
      > > For example in Delphi I would do
      > >
      > > TheString := PreString+ Chr(10) + PostString;
      > >
      > > Where Chr(10) whacks in the ascii character for line feed / carriage[/color]
      > return[color=green]
      > > and prestring and poststring are other strings.
      > >
      > > How do I do this in C#?
      > >
      > > Thanks!
      > >
      > > Lauchlan M
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...