Split string based on the first occurrence of the character

后端 未结 6 1852
南笙
南笙 2020-12-08 12:52

How can I split a C# string based on the first occurrence of the specified character? Suppose I have a string with value:

101,a,b,c,d

I wa

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-08 13:11

    Use string.Split() function. It takes the max. number of chunks it will create. Say you have a string "abc,def,ghi" and you call Split() on it with count parameter set to 2, it will create two chunks "abc" and "def,ghi". Make sure you call it like string.Split(new[] {','}, 2), so the C# doesn't confuse it with the other overload.

提交回复
热议问题