Reputation: 196499
i have a string "ABC DEF EFG" and i want to get an array:
array[0] = "ABC"
array[1] = "DEF EFG"
Upvotes: 1
Views: 643
Reputation: 72870
Use the overload:
"ABC DEF EFG".Split(new char[] { ' ' }, 2)
This limits the number of return parts like you want.
Upvotes: 9
Reputation: 1431
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"
Upvotes: 6