String.Split with a String?

后端 未结 2 1747
日久生厌
日久生厌 2021-01-14 03:00

I have what is probably a very simple question.

I want to do a classic String.Split(), but with a string, not a character. Like string.Split(\"wo

相关标签:
2条回答
  • 2021-01-14 03:39

    You can use String.Split(string[], StringSplitOptions options).

    The code will look like:

    var results = theString.Split(new[] {"word"}, StringSplitOptions.None);
    
    0 讨论(0)
  • 2021-01-14 03:43

    There is an available function overload on string.Split but it takes an array and an enum.

    string test = "1Test2";
    string[] results = test.Split(new string[] { "Test" }, StringSplitOptions.None);
    

    Will yield an array containing "1" and "2".

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