Converts the contents of a delimited string into an Array, removing empty, or whitespace entries.

/// <summary>
/// Convert the <paramref name="content"/> into an array of string,
/// seperated by the specified <see cref="delimiter"/>.
/// </summary>
/// <param name="content">The delimited string content.</param>
/// <param name="delimiter">The delimiter to split on.</param>
/// <returns>An Array of Strings made from contents of <paramref name="content"/>, seperated by <paramref name="delimiter"/>.</returns>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="content"/> is null.</exception>
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="delimiter"/> is less than or equal to zero.</exception>
/// <remarks>Empty values will not be included in the resulting array.</remarks>
public static string[] ToDelimitedArray(string content, char delimiter = ',')
{
    if (content == null)
        throw new ArgumentNullException(nameof(content));

    if (delimiter <= 0)
        throw new ArgumentOutOfRangeException(nameof(delimiter));

    var array = content.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
    var result = new List<string>(array.Length);

    for (var i = 0; i < array.Length; i++)
    {
        var val = array[i].Trim();
        if (!string.IsNullOrEmpty(val))
        {
            result.Add(val);
        }
    }

    return result.ToArray();
}

//
// Xunit Tests

[Theory]
[InlineData("", 0)]
[InlineData(",, ,", 0)]
[InlineData(",two", 1)]
[InlineData("one", 1)]
[InlineData("one,", 1)]
[InlineData("one, ", 1)]
[InlineData("one two three", 1)]
[InlineData("one, two, three", 3)]
public void ShouldSplitStringByDelimiter(string content, int expectedLength)
{
    Assert.True(Common.ToDelimitedArray(content).Length == expectedLength);
}