tags:

views:

92

answers:

1

Hi,

how do i join the results in a IEnumerable to a single string? the IEnumerable contains 20 single letters, and i want it to combine it to a single string.

And out of curiousity: how would i join it with a separator, for example if the IEnumerable contains the strings a b c d e how can i join it to a,b,c,d,e?

Michel

+7  A: 

Try this:

IEnumerable<string> letters = new[] { "a", "b", "c", "d", "e" };
string separator = ", ";
string withSeparator = String.Join(separator, letters.ToArray());
string withoutSeparator = String.Join(String.Empty, letters.ToArray());
Rubens Farias
thanks, looking for linq while the good ol' string has it!
Michel