开发者

how to split a string into an array but only split on the first instance of a character (space in this case)

开发者 https://www.devze.com 2022-12-14 16:05 出处:网络
i have a string \"ABC DEF EFG\" an开发者_Python百科d i want to get an array: array[0] = \"ABC\" array[1] = \"DEF EFG\"Use the overload:

i have a string "ABC DEF EFG" an开发者_Python百科d i want to get an array:

array[0] = "ABC"

array[1] = "DEF EFG"


Use the overload:

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

This limits the number of return parts like you want.


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"

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号