You can easily write one:
public static class StringExtensions { public static IEnumerable<string> Split(this string toSplit, params char[] splits) { if (string.IsNullOrEmpty(toSplit)) yield break; StringBuilder sb = new StringBuilder(); foreach (var c in toSplit) { if (splits.Contains(c)) { yield return sb.ToString(); sb.Clear(); } else { sb.Append(c); } } if (sb.Length > 0) yield return sb.ToString(); } }
Clearly, I have not tested it for parity using string.split, but I believe that it should work in much the same way.
As Servy notes, this is not linebreaking. It is not so simple, but not so effective, but it is basically the same template.
public static IEnumerable<string> Split(this string toSplit, string[] separators) { if (string.IsNullOrEmpty(toSplit)) yield break; StringBuilder sb = new StringBuilder(); foreach (var c in toSplit) { var s = sb.ToString(); var sep = separators.FirstOrDefault(i => s.Contains(i)); if (sep != null) { yield return s.Replace(sep, string.Empty); sb.Clear(); } else { sb.Append(c); } } if (sb.Length > 0) yield return sb.ToString(); }
source share