How to split a string based on every third character regardless of what the character is in c#
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/105770/net-string-format-to-add-commas-in-thousands-place-for-a-number">.NET String.Format() to add commas in thousands place for a number</a>  </p>
</blockquote>



<p>I am trying to add commas to a number for the presentation layer and need to cast and then split the number on every third character in order to join on a ','. </p>

<p>So if i have a string like this </p>

<pre><code>546546555
</code></pre>

<p>desired output:</p>

<pre><code>546,546,555
</code></pre>

<p>Other times, the number could be longer or shorter:</p>

<pre><code>254654
</code></pre>

<p>desired output:</p>

<pre><code>254,654
</code></pre>

<p>Is it possible to split in this manner then join with a comma?</p>

<p>tahnks!</p>

<p>EDIT:</p>

<p>Hi Everyone,</p>

<p>Thanks very much for your help.</p>

<p>To add to this post I also found a way to do this in SQL:</p>

<p>SUBSTRING(CONVERT(varchar, CAST(NumItems AS money), 1), 0, LEN(CONVERT(varchar, CAST(NumDocs AS money), 1)) - 2)  as [NumDocs]</p>
