Split string based on the first occurrence of the character

后端 未结 6 1851
南笙
南笙 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:22

    var pieces = myString.Split(',', 2);
    

    This won't work. The overload will not match and the compiler will reject it.

    So it Must be:

    char[] chDelimiter = {','};
    var pieces = myString.Split(chDelimiter, 2);
    

提交回复
热议问题