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. concatenation of multiple value [modified]

concatenation of multiple value [modified]

Scheduled Pinned Locked Moved C#
databasetutorial
8 Posts 6 Posters 1 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.
  • V Offline
    V Offline
    varsh12
    wrote on last edited by
    #1

    hii! please guide me regarding: i want concatenate "welcome", "to", "hello" and "world" together. like as: welcome to hello world these value are coming from via for loop. but if in case I don't know what the actually data store in database. what i do thanx thanx for every one:

    modified on Saturday, July 10, 2010 8:17 AM

    L OriginalGriffO D P A 5 Replies Last reply
    0
    • V varsh12

      hii! please guide me regarding: i want concatenate "welcome", "to", "hello" and "world" together. like as: welcome to hello world these value are coming from via for loop. but if in case I don't know what the actually data store in database. what i do thanx thanx for every one:

      modified on Saturday, July 10, 2010 8:17 AM

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

      Console.WriteLine("helloworld");

      :omg:

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      1 Reply Last reply
      0
      • V varsh12

        hii! please guide me regarding: i want concatenate "welcome", "to", "hello" and "world" together. like as: welcome to hello world these value are coming from via for loop. but if in case I don't know what the actually data store in database. what i do thanx thanx for every one:

        modified on Saturday, July 10, 2010 8:17 AM

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        Try:

        string result = "welcome" + "to" + "hello" + "world";
        string resultWithSpaces = string.Format("{0} {1} {2} {3}", "welcome", "to", "hello", "world");

        Each literal string "whatever" could be a variable string ion either case:

        string strWelcome = "welcome";
        string strTo = "to";
        string strHello = "hello";
        string strWorld = "world";
        string result = strWelcome + strTo + strHello + strWorld;
        string resultWithSpaces = string.Format("{0} {1} {2} {3}", strWelcome, strTo, strHello, strWorld);

        If you need them in a loop:

        string[] text = {"welcome", "to", "hello", "world"};
        string result = "";
        string resultWithSpaces = "";
        foreach (string s in text)
        {
        result += s;
        resultWithSpaces += s + " ";
        }

        The advanced stuff is to use a StringBuilder, but that can wait until you are certain of the basics!

        Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        D 1 Reply Last reply
        0
        • V varsh12

          hii! please guide me regarding: i want concatenate "welcome", "to", "hello" and "world" together. like as: welcome to hello world these value are coming from via for loop. but if in case I don't know what the actually data store in database. what i do thanx thanx for every one:

          modified on Saturday, July 10, 2010 8:17 AM

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          Three easy options, +, string.Format or StringBuilder The first two...

          string newString = "welcome" + "to" + "hello" + "world";
          string newString = string.Format("{0} {1} {2} {3}", "welcome", "to", "hello", "world");

          Dave

          If this helped, please vote & accept answer!

          Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

          1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Try:

            string result = "welcome" + "to" + "hello" + "world";
            string resultWithSpaces = string.Format("{0} {1} {2} {3}", "welcome", "to", "hello", "world");

            Each literal string "whatever" could be a variable string ion either case:

            string strWelcome = "welcome";
            string strTo = "to";
            string strHello = "hello";
            string strWorld = "world";
            string result = strWelcome + strTo + strHello + strWorld;
            string resultWithSpaces = string.Format("{0} {1} {2} {3}", strWelcome, strTo, strHello, strWorld);

            If you need them in a loop:

            string[] text = {"welcome", "to", "hello", "world"};
            string result = "";
            string resultWithSpaces = "";
            foreach (string s in text)
            {
            result += s;
            resultWithSpaces += s + " ";
            }

            The advanced stuff is to use a StringBuilder, but that can wait until you are certain of the basics!

            Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

            D Offline
            D Offline
            DaveyM69
            wrote on last edited by
            #5

            Sorry, didn't see your post! :doh:

            Dave

            If this helped, please vote & accept answer!

            Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

            OriginalGriffO 1 Reply Last reply
            0
            • D DaveyM69

              Sorry, didn't see your post! :doh:

              Dave

              If this helped, please vote & accept answer!

              Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
              BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              I do that as well... :laugh: (mostly, I tend to do it with the CCC - damnit!)

              Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              1 Reply Last reply
              0
              • V varsh12

                hii! please guide me regarding: i want concatenate "welcome", "to", "hello" and "world" together. like as: welcome to hello world these value are coming from via for loop. but if in case I don't know what the actually data store in database. what i do thanx thanx for every one:

                modified on Saturday, July 10, 2010 8:17 AM

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                Look into System.Text.StringBuilder.

                1 Reply Last reply
                0
                • V varsh12

                  hii! please guide me regarding: i want concatenate "welcome", "to", "hello" and "world" together. like as: welcome to hello world these value are coming from via for loop. but if in case I don't know what the actually data store in database. what i do thanx thanx for every one:

                  modified on Saturday, July 10, 2010 8:17 AM

                  A Offline
                  A Offline
                  Abhinav S
                  wrote on last edited by
                  #8

                  I do assume you know how to concatenate two strings and if you don't you should get a C# book and go through it. If you are not sure what order they words are coming from the database in, I'm afraid you cannot do a 'grammatically correct' concatenation unless you build your own language parser. That would mean writing tons of parsing logic and building your own language database.

                  The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.

                  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