Define a multiple line long string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • huohaodian@gmail.com

    Define a multiple line long string

    Hi,

    How can I define a long string variable in C# with multiple lines ?

    For example

    private string longName = "aaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaa"

    "bbbbbbbbbbbbbb bbbbbbbbbbbbbbb bbbbbbbbbb";
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Define a multiple line long string

    Are you talking about concatenating them? You can always do this:

    private string longName = "aaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaa" +
    "bbbbbbbbbbbbbb bbbbbbbbbbbbbbb bbbbbbbbbb";

    The compiler will concatenate it at compile-time into one string.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    <huohaodian@gma il.comwrote in message
    news:613fb90f-24bf-40e3-80d9-3e316825637c@i7 g2000prf.google groups.com...
    Hi,
    >
    How can I define a long string variable in C# with multiple lines ?
    >
    For example
    >
    private string longName = "aaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaa"
    >
    "bbbbbbbbbbbbbb bbbbbbbbbbbbbbb bbbbbbbbbb";

    Comment

    • .\\\\axxx

      #3
      Re: Define a multiple line long string

      Just stick a '+' at the end of the first line.

      On Feb 12, 7:47 am, huohaod...@gmai l.com wrote:
      Hi,
      >
      How can I define a long string variable in C# with multiple lines ?
      >
      For example
      >
      private string longName = "aaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaa"
      >
      "bbbbbbbbbbbbbb bbbbbbbbbbbbbbb bbbbbbbbbb";

      Comment

      • christery@gmail.com

        #4
        Re: Define a multiple line long string

        hmm, if there is a long string, is there a double string (UTF-32/64?)
        an signed string, maybe a booldean string? thsi is Zen at high level..
        ah the boolena string is True/False, got 4-5 char in a bit...

        ;)

        Just kidding...

        //CY

        Comment

        • =?ISO-8859-1?Q?Bj=F8rn_Brox?=

          #5
          Re: Define a multiple line long string

          christery@gmail .com skrev:
          On 11 Feb, 22:47, huohaod...@gmai l.com wrote:
          >Hi,
          >>
          > How can I define a long string variable in C# with multiple lines ?
          >>
          > For example
          >>
          > private string longName = "aaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaa"
          >>
          >"bbbbbbbbbbbbb bbbbbbbbbbbbbbb bbbbbbbbbbb";
          >
          What is multiple lines? how long is a string as in a thread, the
          physical piece of string I mean..
          >
          just "+" to concatenate, char 13/10 or is it 10/13 will break lines
          when displaying them .. CR/LF maybe just CR (13) who knows... that up
          to the receiver of the string...
          >
          \r \n are normally used for this...
          >
          Instead of guessing you can use Environment.New Line

          private string longName =
          "aaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaa" + Environment.New Line +
          "bbbbbbbbbbbbbb bbbbbbbbbbbbbbb bbbbbbbbbb";
          >
          --
          Bjørn Brox

          Comment

          • Jon Skeet [C# MVP]

            #6
            Re: Define a multiple line long string

            On Feb 12, 9:13 am, Bjørn Brox <bpb...@gmail.c omwrote:

            <snip>
            Instead of guessing you can use Environment.New Line
            >
            private string longName =
            "aaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaa" + Environment.New Line +
            "bbbbbbbbbbbbbb bbbbbbbbbbbbbbb bbbbbbbbbb";
            And that's fine so long as you want it to use the platform default of
            the operating system you're on - but there's more context than that.
            Is it the same for an email body, for instance? How about telnet?

            Environment.New Line is a beguiling property because it leads to the
            impression that you never need to worry about new lines again. That's
            just untrue - you need to work out the context for your data, and what
            the new line for that context is.

            Jon

            Comment

            • christery@gmail.com

              #7
              Re: Define a multiple line long string

              On 12 Feb, 10:17, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
              On Feb 12, 9:13 am, Bjørn Brox <bpb...@gmail.c omwrote:
              >
              <snip>
              >
              Instead of guessing you can use Environment.New Line
              >
              private string longName =
                   "aaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaa" + Environment.New Line +
                   "bbbbbbbbbbbbbb bbbbbbbbbbbbbbb bbbbbbbbbb";
              >
              And that's fine so long as you want it to use the platform default of
              the operating system you're on - but there's more context than that.
              Is it the same for an email body, for instance? How about telnet?
              >
              Environment.New Line is a beguiling property because it leads to the
              impression that you never need to worry about new lines again. That's
              just untrue - you need to work out the context for your data, and what
              the new line for that context is.
              >
              Jon
              [STX] yup, Im working with communications a bit, and what environment
              im sitting on/in is not telling me what im communicating with is
              accepting (yet anyways) [ETX]
              that why the example, it wipes "dont" as you all realised, oh s*it
              getting OT again... rereading the Q, the answer is + or @ as posted
              earlyer by others...
              //CY

              Comment

              Working...