<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>crunchlife: Yet Another Join Method</title>
    <link>http://crunchlife.com/articles/2008/09/12/yet-another-join-method</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Yet Another Join Method</title>
      <description>&lt;p&gt;The .NET String type has a &lt;a href="http://msdn.microsoft.com/en-us/library/57a79xd0.aspx" target="_blank"&gt;Join method&lt;/a&gt;, but in my latest ASP.NET project I had the need for joining String array elements with additional prefix and suffix values. The method below delimits array elements with the provided separator and concatenates the elements with the prefix and suffix string parameters.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve found this particularly handy when creating SQL statements that require the IN keyword.&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;string[] names = { &amp;quot;Bobby&amp;quot;, &amp;quot;Suzy&amp;quot; };

sql += &amp;quot;WHERE People.FirstName IN (&amp;quot; + Utility.Join(&amp;quot;,&amp;quot;, names, &amp;quot;'&amp;quot;, &amp;quot;'&amp;quot;) + &amp;quot;)&amp;quot;;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Add this method to your utility class or extended String type.&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;public static string Join(string separator, string[] value, string
prefix, string suffix)
{
    string toReturn = String.Empty;

    int i;
    for (i = 0; i &amp;lt; value.Length; i++)
    {
        if (i != value.Length - 1)
            toReturn += prefix + value[i] + suffix + separator;
        else
            toReturn += prefix + value[i] + suffix;
    }

    return toReturn;
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
      <pubDate>Fri, 12 Sep 2008 14:27:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:05392c66-db31-4f67-80a6-e73740c41523</guid>
      <author>Ryan Baxter</author>
      <link>http://crunchlife.com/articles/2008/09/12/yet-another-join-method</link>
      <category>Code Snippets</category>
      <category>CSharp</category>
      <category>dotNET</category>
    </item>
    <item>
      <title>"Yet Another Join Method" by Tracy Hopper</title>
      <description>4eixm9bnlzdyv3kn
</description>
      <pubDate>Wed, 12 Nov 2008 14:11:05 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:20a92373-663d-4946-a105-6b6b15fd50c0</guid>
      <link>http://crunchlife.com/articles/2008/09/12/yet-another-join-method#comment-10134</link>
    </item>
  </channel>
</rss>

