how do you split a string with a string in C#

后端 未结 2 2269
借酒劲吻你
借酒劲吻你 2021-02-20 12:38

I would like to split a string into a String[] using a String as a delimiter.

String delimit = \"[break]\";
String[] tokens = myString.Split(delimit);

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-20 12:59

    Like this:

    mystring.Split(new string[] { delimit }, StringSplitOptions.None);
    

    For some reason, the only overloads of Split that take a string take it as an array, along with a StringSplitOptions.
    I have no idea why there isn't a string.Split(params string[]) overload.

提交回复
热议问题