2

Break a String array of size 5 into two parts 2 & 3 string arrays?

Orignal

String Array[] = {"asjjsjamsssssssssssssssssssssss",
                  "hcb j m dnfijvkfkjvkjdffkbdfblllfl",
                  "bjbvfumfkkf md",
                  "jdsjvjsdjvjjjjdjjdj",
                  "bsdjdddddddddddddddddddddddd"}

Resulting String contains 2 & 3 strings.

2
  • 2
    What is your desired output? "hcb md"? Commented Apr 4, 2012 at 6:49
  • 1
    The quickest way is to not do it. With ArraySegment<> Commented Apr 4, 2012 at 15:06

2 Answers 2

1

Try this below.

    string[] arr  = {"asjjsjamsssssssssssssssssssssss",
                               "hcb j m dnfijvkfkjvkjdffkbdfblllfl",
                                "bjbvfumfkkf md",
                                "jdsjvjsdjvjjjjdjjdj",
                                  "bsdjdddddddddddddddddddddddd"};

var first = arr.Take(2).ToArray();
var second = arr.Skip(2).Take(3).ToArray();
Sign up to request clarification or add additional context in comments.

1 Comment

+1 just for understanding the question :-) It did not make sense to me until I saw your answer.
0

You will never be able to break string array unless the number of elements in array are even. Rethink about your operation.

1 Comment

Yes, i think you r right. Real question is that I have a data table & trying to covert it into the string array to break it into two parts.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.