Added simple String.Split extension
[IEnumerableExtras.git] / C# / EnumerableJoin.cs
blob886e03234decde3bdca2d49944e9837e474e79e3
1 using System.Collections.Generic;
2 using System.Text;
4 namespace IEnumerableExtras
6 /// <summary>
7 /// Provide <see cref="IEnumerable{T}"/> with Join extension method.
8 /// </summary>
9 public static class EnumerableJoin
11 /// <summary>
12 /// Join all members of this <see cref="IEnumerable{T}"/> to a single string using <paramref name="glue"/>
13 /// as a separator.
14 /// </summary>
15 /// <typeparam name="T"></typeparam>
16 /// <param name="enumerable"></param>
17 /// <param name="glue"></param>
18 /// <returns></returns>
19 public static string Join<T>(this IEnumerable<T> enumerable, string glue)
21 return enumerable.Reduce( new StringBuilder(), ( sb, item ) => sb.Length == 0 ? sb.Append( item ) : sb.Append( glue ).Append( item ) ).ToString();