Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's impossible to give a truly language-agnostic answer here as different languages and platforms handle strings differently, and provide different levels of built-in support for joining lists of strings. You could take pretty much <em>identical</em> code in two different languages, and it would be great in one and awful in another.</p> <p>In C#, you could use:</p> <pre><code>StringBuilder builder = new StringBuilder(); string delimiter = ""; foreach (string item in list) { builder.Append(delimiter); builder.Append(item); delimiter = ","; } return builder.ToString(); </code></pre> <p>This will <em>prepend</em> a comma on all but the first item. Similar code would be good in Java too.</p> <p>EDIT: Here's an alternative, a bit like Ian's later answer but working on a general <code>IEnumerable&lt;string&gt;</code>.</p> <pre><code>// Change to IEnumerator for the non-generic IEnumerable using (IEnumerator&lt;string&gt; iterator = list.GetEnumerator()) { if (!iterator.MoveNext()) { return ""; } StringBuilder builder = new StringBuilder(iterator.Current); while (iterator.MoveNext()) { builder.Append(delimiter); builder.Append(iterator.Current); } return builder.ToString(); } </code></pre> <p>EDIT nearly 5 years after the original answer...</p> <p>In .NET 4, <a href="http://msdn.microsoft.com/en-us/library/system.string.join%28v=vs.100%29.aspx" rel="noreferrer"><code>string.Join</code></a> was overloaded pretty significantly. There's an overload taking <code>IEnumerable&lt;T&gt;</code> which automatically calls <code>ToString</code>, and there's an overload for <code>IEnumerable&lt;string&gt;</code>. So you don't need the code above any more... for .NET, anyway.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload