Click here to Skip to main content
13,866,278 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


Posted 28 Jun 2011
Licenced CPOL

String concatenation using LINQ to create a CSV/PSV string

, 29 Jun 2011
Rate this:
Please Sign up or sign in to vote.
I rather like IEnumerable than IList, parameters should be as general as posible. I think it's really getting very fun up here. Here's my choice, just for strings.public static string Join(this IEnumerable parts, string separator){ if (! parts.Any()) return...
I rather like IEnumerable<T> than IList<T>, parameters should be as general as posible. I think it's really getting very fun up here. Here's my choice, just for strings.

public static string Join(this IEnumerable<string> parts, string separator)
    if (! parts.Any())
        return string.Empty;

    var builder = new StringBuilder();

    builder.Append(parts.First()) ;

    foreach(var part in parts.Skip(1))
        builder.Append(separator) ;

    return builder.ToString();


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Erich Ledesma
Architect SunHotels
Spain Spain
I Received a Bachelor's Degree in Computer Science at the Mathematics and Computer Science Faculty, University of Havana, Cuba.

I mainly work in web applications using C# and some Javascript. Some very few times do some Java.

You may also be interested in...


Comments and Discussions

GeneralConsider escaping the separator character within 'part' befo... Pin
TrevorJF5-Jul-11 4:31
memberTrevorJF5-Jul-11 4:31 
GeneralRe: Separator is a string, so it's already "escaped". string.Joi... Pin
Erich Ledesma6-Jul-11 9:55
memberErich Ledesma6-Jul-11 9:55 
GeneralReason for my vote of 5 Good, Simpler and easy to implement ... Pin
All Time Programming4-Jul-11 21:57
memberAll Time Programming4-Jul-11 21:57 
GeneralI agree :) Pin
Mohammad A Rahman28-Jun-11 4:01
memberMohammad A Rahman28-Jun-11 4:01 
GeneralReason for my vote of 5 Reason of my vote 5: I like the rhyt... Pin
Mohammad A Rahman28-Jun-11 3:53
memberMohammad A Rahman28-Jun-11 3:53 
GeneralRe: Thanx mate. The idea is always trying to make it as simple a... Pin
Erich Ledesma28-Jun-11 3:57
memberErich Ledesma28-Jun-11 3:57 
GeneralI agree, it could be generic, and would be usefull. But in m... Pin
Erich Ledesma28-Jun-11 3:45
memberErich Ledesma28-Jun-11 3:45 
GeneralNice one :) Pin
Mohammad A Rahman28-Jun-11 3:45
memberMohammad A Rahman28-Jun-11 3:45 
GeneralWhy only for the strings? Could be a generic T as Append acc... Pin
Mario Majčica28-Jun-11 3:34
professionalMario Majčica28-Jun-11 3:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190214.1 | Last Updated 29 Jun 2011
Article Copyright 2011 by Erich Ledesma
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid