Created
February 28, 2017 14:38
-
-
Save pgsin/5fb86df4d88279bebe37c288d32d3a82 to your computer and use it in GitHub Desktop.
BaseLibS.Utils.StringUtils.Concat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace Test { | |
public class Program { | |
static void Main() { | |
Console.WriteLine(Concat(",",new List<string> {"a","b","c"})); | |
} | |
public static string Concat<T>(string separator, IEnumerable<T> o) { | |
if (o == null) { | |
return ""; | |
} | |
IEnumerator<T> oe = o.GetEnumerator(); | |
if (!oe.MoveNext()) return ""; | |
StringBuilder s = new StringBuilder(); | |
s.Append(oe.Current); | |
while (oe.MoveNext()) { | |
s.Append(separator + oe.Current); | |
} | |
return s.ToString(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment