开发者

String.Split in .Net FW - why no overload that takes a single string?

开发者 https://www.devze.com 2023-01-07 03:32 出处:网络
...e.g. Str开发者_如何转开发ing.Split(Delim As String).Yes, it is odd, have cursed at it myself several times.Equally odd is that the Split() overloads that take a string were not available in .NET 1.

...e.g. Str开发者_如何转开发ing.Split(Delim As String).


Yes, it is odd, have cursed at it myself several times. Equally odd is that the Split() overloads that take a string were not available in .NET 1.x. Well, odder perhaps. Maybe some "not too many overloads!" paralysis here. The StringSplitOptions and Count arguments can generate a combinatorial number of them.

Fix it with an extension method:

public static class Extensions {
    public static string[] Split(this string s, string separator) {
        return s.Split(new string[] { separator }, StringSplitOptions.None);
    }
}

And add the ones you need if you also want to cover StringSplitOptions and Count :)

0

精彩评论

暂无评论...
验证码 换一张
取 消