Split string array

Go To StackoverFlow.com

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.

2012-04-04 06:46
by jhonnash
What is your desired output? "hcb md" - Anders Lindahl 2012-04-04 06:49
The quickest way is to not do it. With ArraySegment<> - Hans Passant 2012-04-04 15:06


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();
2012-04-04 06:51
by scartag
+1 just for understanding the question :-) It did not make sense to me until I saw your answer - Eric J. 2012-04-04 06:53


0

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

2012-04-04 06:52
by Ravi Jain
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 - jhonnash 2012-04-04 10:23
Ads