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

后端 未结 2 2268
借酒劲吻你
借酒劲吻你 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:55

    I personally prefer to use something like this, since regex has that split:

    public static string[] Split(this string input, string delimit)
    {
      return Regex.Split(input, delimit);
    }
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题