Skip to content

Commit

Permalink
Added the UnSplit() extension method (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Jan 8, 2023
1 parent b3420cb commit a4dea8a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions PeyrSharp.Extensions/ArrayExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,21 @@ public static T[] RemoveElement<T>(this T[] array, params T[] items)

return list.ToArray(); // Return the new array
}

/// <summary>
/// Concatenates the elements of a string array, using the specified separator between each element.
/// </summary>
/// <param name="array">The array of strings to concatenate.</param>
/// <param name="separator">The string to use as a separator.</param>
/// <returns>A string that consists of the elements of <paramref name="array"/> delimited by the <paramref name="separator"/> string. If <paramref name="array"/> has no elements, the method returns an empty string.</returns>
public static string UnSplit(this string[] array, string separator)
{
string final = "";
for (int i = 0; i < array.Length; i++)
{
final += array[i] + ((i < array.Length) ? separator : "");
}
return final;
}
}
}

0 comments on commit a4dea8a

Please sign in to comment.