In C# if I want to split a string
by another string
I have to do something like that :
testString.Split(new string[] { "anotherString" }, StringSplitOptions.None);
From the overloaded String.Split
MSDN Documentation we can see the implementation and why such a call has to be made.
Coming from Python, It is hard for me to understand correctly why such a call is needed. I mean I could use Regex.Split
to get a similar syntax than the Python's implementation but I would have to do it at the cost of less performance (setup time) for anything simple.
So basically, my question is why the hell can't we just do:
testString.Split("anotherString");
Note that I'm not suggesting any prototype nor implementation. I understand why you couldn't implement the above version considering the current API. My goal was to understand why such an API could have been created considering the benefit that the above syntax brings. As of now, flexibility seems to be the goal of the current String.Split
which make sense, but to be honest I really thought there was some sort of performance gain somewhere. I guess I was wrong.
testString.Split(",.;");
andtestString.Split(new Char [] {',', '.', ';',);
which are not the same thing.IEnumerable<char>
so the additional prototype you are suggesting might appear ambiguous in certain cases (do you delimit by the whole string or delimit by each of its characters?) Just a guess.testString.Split("anotherString");
, I'm pretty confident to say that the expected behavior was to delimit on the whole string (anotherString
in this case).