feat: Extension methods for joining enumerables of strings

This commit is contained in:
Chris Cameron
2021-03-23 17:05:27 -04:00
parent e7bdcdfca5
commit 370cadbaeb

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using ICD.Common.Properties; using ICD.Common.Properties;
@@ -142,6 +143,46 @@ namespace ICD.Common.Utils.Extensions
Math.Min(chunkSize, extends.Length - (i * chunkSize)))); Math.Min(chunkSize, extends.Length - (i * chunkSize))));
} }
/// <summary>
/// Joins the strings in the enumerable.
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static string Join([NotNull] this IEnumerable<string> extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
return extends.Join(string.Empty);
}
/// <summary>
/// Joins the strings in the enumerable.
/// </summary>
/// <param name="extends"></param>
/// <param name="delimiter"></param>
/// <returns></returns>
public static string Join([NotNull] this IEnumerable<string> extends, string delimiter)
{
if (extends == null)
throw new ArgumentNullException("extends");
StringBuilder builder = new StringBuilder();
bool isFirst = true;
foreach (string item in extends)
{
if (!isFirst)
builder.Append(delimiter);
builder.Append(item);
isFirst = false;
}
return builder.ToString();
}
/// <summary> /// <summary>
/// Removes whitespace from the string. /// Removes whitespace from the string.
/// </summary> /// </summary>