mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-12 03:57:32 +00:00
feat: Extension methods for joining enumerables of strings
This commit is contained in:
parent
e7bdcdfca5
commit
370cadbaeb
1 changed files with 41 additions and 0 deletions
|
|
@ -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>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue