public string Test_SplitText_DelimiterType(string text, string delimiters, StringSplitOptions options, SplitDelimiterType delimiterType) { var result = text.SplitText(delimiters, options, delimiterType); return(string.Join(",", result)); }
/// <summary> /// Splits the text by the specified delimiters. /// </summary> /// <param name="text">The text.</param> /// <param name="delimiters">The delimiters.</param> /// <param name="options">The options.</param> /// <param name="delimiterType">Type of the delimiter.</param> /// <returns>IEnumerable<System.String>.</returns> /// <exception cref="ArgumentOutOfRangeException">delimiterType - Value must be one of {string.Join(",", Enum.GetNames(typeof(SplitDelimiterType)))}</exception> /// <remarks>Also available as an extension method</remarks> public static IEnumerable <string> SplitText(this string text, string delimiters, StringSplitOptions options = StringSplitOptions.None, SplitDelimiterType delimiterType = SplitDelimiterType.Any) { switch (delimiterType) { case SplitDelimiterType.Any: return(text.Split(delimiters.ToCharArray(), options)); case SplitDelimiterType.All: // NOTE: A native text.Split(string, ...) is available in NET Core 2.1+ return(text.SplitByText(delimiters, options)); default: throw new ArgumentOutOfRangeException(nameof(delimiterType), delimiterType, $"Value must be one of {string.Join(",", Enum.GetNames(typeof(SplitDelimiterType)))}"); } }