using System; namespace EmbedIO.Utilities { /// /// Provides extension methods for . /// public static class StringExtensions { private static readonly char[] CommaSplitChars = {','}; /// Splits a string into substrings based on the specified . /// The returned array includes empty array elements if two or more consecutive delimiters are found /// in . /// The on which this method is called. /// An array of s to use as delimiters. /// An array whose elements contain the substrings in that are delimited /// by one or more characters in . /// is . public static string[] SplitByAny(this string @this, params char[] delimiters) => @this.Split(delimiters); /// Splits a string into substrings, using the comma (,) character as a delimiter. /// The returned array includes empty array elements if two or more commas are found in . /// The on which this method is called. /// An array whose elements contain the substrings in that are delimited by commas. /// is . /// public static string[] SplitByComma(this string @this) => @this.Split(CommaSplitChars); /// Splits a string into substrings, using the comma (,) character as a delimiter. /// You can specify whether the substrings include empty array elements. /// The on which this method is called. /// to omit empty array elements from the array returned; /// or to include empty array elements in the array returned. /// /// An array whose elements contain the substrings in that are delimited by commas. /// For more information, see the Remarks section of the method. /// /// is . /// options is not one of the values. /// public static string[] SplitByComma(this string @this, StringSplitOptions options) => @this.Split(CommaSplitChars, options); /// /// Ensures that a is never empty, /// by transforming empty strings into . /// /// The on which this method is called. /// If is the empty string, ; /// otherwise, public static string? NullIfEmpty(this string @this) => string.IsNullOrEmpty(@this) ? null : @this; } }