tags:

views:

65

answers:

2

i have a string "ABC DEF EFG" and i want to get an array:

array[0] = "ABC"
array[1] = "DEF EFG"

+9  A: 

Use the overload:

"ABC DEF EFG".Split(new char[] { ' ' }, 2)

This limits the number of return parts like you want.

David M
The given syntax is not correct. The first argument is a character array. See Eric's answer.
Richard Szalay
Thanks. Corrected
David M
+3  A: 

You can use the Split method with a number indicating the maximum number of array elements to return:

"ABC DEF EFG".Split(new char[] {' '}, 2)

will return "ABC" and "DEF EFG"

Eric Minkes