If you have this code:
"......".Split(new String[]{"...", ".."}, StringSplitOptions.None);
The resulting array elements are:
1. ""
2. ""
3. ""
Now if you reverse the order of the separators,
"......".Split(new String[]{"..", "..."}, StringSplitOptions.None);
The resulting array elements are:
1. ""
2. ""
3. ""
4. ""
From these 2 examples I feel inclined to conclude that the Split method recursively tokenizes as it goes through each element of the array from left to right.
However, once we throw in separators that contain alphanumeric characters into the equation, it is clear that the above theory is wrong.
"5.x.7".Split(new String[]{".x", "x."}, StringSplitOptions.None)
results in: 1. "5" 2. ".7"
"5.x.7".Split(new String[]{"x.", ".x"}, StringSplitOptions.None)
results in: 1. "5" 2. ".7"
This time we obtain the same output, which means that the rule theorized based on the first set of examples no longer applies. (ie: if separator precedence was always determined based on the position of the separator within the array, then in the last example we would have obtained "5."
& "7"
instead of "5"
& ".7"
.
As to why I am wasting my time trying to guess how .NET standard API's work, it's because I want to implement similar functionality for my java apps, but neither StringTokenizer nor org.apache.commons.lang.StringUtils provide the ability to split a String using multiple multi-character separators (and even if I were to find an API that does provide this ability, it would be hard to know if it always tokenizes using the same algorithm used by the String.Split method.