Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. splitting a long string

splitting a long string

Scheduled Pinned Locked Moved C#
csharpc++question
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    manustone
    wrote on last edited by
    #1

    Hi All Do you know if it is possible to split a string in several lines in C# In C++ I can write

    std::cout << "this is a very "
    "very very very "
    "very very very "
    "long string split into 4 lines that will be printed in one";

    Do you know if I can do the same in C#? Thanks MN

    K K 2 Replies Last reply
    0
    • M manustone

      Hi All Do you know if it is possible to split a string in several lines in C# In C++ I can write

      std::cout << "this is a very "
      "very very very "
      "very very very "
      "long string split into 4 lines that will be printed in one";

      Do you know if I can do the same in C#? Thanks MN

      K Offline
      K Offline
      Keith Barrow
      wrote on last edited by
      #2

      Yes:

      Console.WriteLine( "this is a very " +
      "very very very " +
      "very very very " +
      "long string split into 4 lines that will be printed in one");

      Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.

      M 1 Reply Last reply
      0
      • M manustone

        Hi All Do you know if it is possible to split a string in several lines in C# In C++ I can write

        std::cout << "this is a very "
        "very very very "
        "very very very "
        "long string split into 4 lines that will be printed in one";

        Do you know if I can do the same in C#? Thanks MN

        K Offline
        K Offline
        kevinnicol
        wrote on last edited by
        #3

        could try this

        Console.WriteLine(@"this is a very
        very very very
        very very very
        long string split into 4 lines that will be printed in one")

        M 1 Reply Last reply
        0
        • K kevinnicol

          could try this

          Console.WriteLine(@"this is a very
          very very very
          very very very
          long string split into 4 lines that will be printed in one")

          M Offline
          M Offline
          manustone
          wrote on last edited by
          #4

          Thanks, but I need the string on the same line not on different lines. When I have to print that I will see the new line I guess.

          L 1 Reply Last reply
          0
          • K Keith Barrow

            Yes:

            Console.WriteLine( "this is a very " +
            "very very very " +
            "very very very " +
            "long string split into 4 lines that will be printed in one");

            Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.

            M Offline
            M Offline
            manustone
            wrote on last edited by
            #5

            Hi Thanks! Is there any other way without the + char at the end? For each + I think that C# due to how the String are will create in memory a new object that is the result of "String1" + "String2". I need just some facility so that compiler will recognize that it must print on the same line. This was the purpose of my questions even if I didn't make it explicit

            L 1 Reply Last reply
            0
            • M manustone

              Hi Thanks! Is there any other way without the + char at the end? For each + I think that C# due to how the String are will create in memory a new object that is the result of "String1" + "String2". I need just some facility so that compiler will recognize that it must print on the same line. This was the purpose of my questions even if I didn't make it explicit

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Hi, the C# compiler understands concatenation of string literals and executes them once, while compiling. It all results in one big string literal before your code actually gets executed, just the way you intended it. You could check with Reflector[^]. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
              All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.


              modified on Friday, February 26, 2010 12:57 PM

              1 Reply Last reply
              0
              • M manustone

                Thanks, but I need the string on the same line not on different lines. When I have to print that I will see the new line I guess.

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                manustone wrote:

                I guess

                X| Read the documentation; perform an experiment; don't guess.

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
                All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.


                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups