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. How to join 2 string[] objects

How to join 2 string[] objects

Scheduled Pinned Locked Moved C#
questiondata-structurestutorial
7 Posts 6 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.
  • C Offline
    C Offline
    Chesnokov Yuriy
    wrote on last edited by
    #1

    Is there a single function that takes 2 string[] arrays and concatenates them together in a single string[] array?

    string[] s1 = { "one", "two" };
    string[] s2 = { "three", "four" };
    // what is the function to produce that one?
    string[] s = { "one", "two", "three", "four" };

    Чесноков

    R F A L R 5 Replies Last reply
    0
    • C Chesnokov Yuriy

      Is there a single function that takes 2 string[] arrays and concatenates them together in a single string[] array?

      string[] s1 = { "one", "two" };
      string[] s2 = { "three", "four" };
      // what is the function to produce that one?
      string[] s = { "one", "two", "three", "four" };

      Чесноков

      R Offline
      R Offline
      R Giskard Reventlov
      wrote on last edited by
      #2

      Use CopyTo[^].

      "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

      1 Reply Last reply
      0
      • C Chesnokov Yuriy

        Is there a single function that takes 2 string[] arrays and concatenates them together in a single string[] array?

        string[] s1 = { "one", "two" };
        string[] s2 = { "three", "four" };
        // what is the function to produce that one?
        string[] s = { "one", "two", "three", "four" };

        Чесноков

        F Offline
        F Offline
        freakyit
        wrote on last edited by
        #3

        System.Collections.Generic.List<string> lst = new System.Collections.Generic.List<string>(); lst.AddRange(s1); lst.AddRange(s2); string[] s = new string[lst.Count]; lst.CopyTo(s); lst.Clear(); lst = null;

        1 Reply Last reply
        0
        • C Chesnokov Yuriy

          Is there a single function that takes 2 string[] arrays and concatenates them together in a single string[] array?

          string[] s1 = { "one", "two" };
          string[] s2 = { "three", "four" };
          // what is the function to produce that one?
          string[] s = { "one", "two", "three", "four" };

          Чесноков

          A Offline
          A Offline
          Ayman Kouzayha
          wrote on last edited by
          #4

          simple table management string[] s = new string[s1.Length + s2.Length]; int _sCounter = 0; for(int i=0;i

          1 Reply Last reply
          0
          • C Chesnokov Yuriy

            Is there a single function that takes 2 string[] arrays and concatenates them together in a single string[] array?

            string[] s1 = { "one", "two" };
            string[] s2 = { "three", "four" };
            // what is the function to produce that one?
            string[] s = { "one", "two", "three", "four" };

            Чесноков

            L Offline
            L Offline
            Laxman Auti
            wrote on last edited by
            #5

            Chesnokov Yuriy wrote:

            Is there a single function that takes 2 string[] arrays and concatenates them together in a single string[] array?

            I think following function will do the stuff, right?

            public static string[] ConcateArray(string[] s1, string[] s2)
            {
            string[] s = new string[s1.Length + s2.Length];
            s1.CopyTo(s, 0);
            s2.CopyTo(s, s1.Length);
            return s;
            }

            Just call the method as

            string[] s = ConcateArray(s1, s2);

            Knock out 't' from can't, you can if you think you can. :cool:

            C 1 Reply Last reply
            0
            • L Laxman Auti

              Chesnokov Yuriy wrote:

              Is there a single function that takes 2 string[] arrays and concatenates them together in a single string[] array?

              I think following function will do the stuff, right?

              public static string[] ConcateArray(string[] s1, string[] s2)
              {
              string[] s = new string[s1.Length + s2.Length];
              s1.CopyTo(s, 0);
              s2.CopyTo(s, s1.Length);
              return s;
              }

              Just call the method as

              string[] s = ConcateArray(s1, s2);

              Knock out 't' from can't, you can if you think you can. :cool:

              C Offline
              C Offline
              Chesnokov Yuriy
              wrote on last edited by
              #6

              That will work though there is no inherent .NET function. I wich I had such a plethora of answers to that question ;) http://www.codeproject.com/Messages/3519974/How-to-invoke-native-MyFunction-MyStruct-myStructs.aspx[^]

              Чесноков

              1 Reply Last reply
              0
              • C Chesnokov Yuriy

                Is there a single function that takes 2 string[] arrays and concatenates them together in a single string[] array?

                string[] s1 = { "one", "two" };
                string[] s2 = { "three", "four" };
                // what is the function to produce that one?
                string[] s = { "one", "two", "three", "four" };

                Чесноков

                R Offline
                R Offline
                Ravi Bhavnani
                wrote on last edited by
                #7

                See String.Join()[^]. /ravi

                My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                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