title: Formatting alphanumeric string
body: <p>I have a string with 16 alphanumeric characters, e.g. F4194E7CC775F003. I'd like to format it as F419-4E7C-C775-F003.</p>
  
  <p>I tried using</p>
  
  <pre><code>string.Format("{0:####-####-####-####}","F4194E7CC775F003");
  </code></pre>
  
  <p>but this doesn't work since it's not a numeric value.</p>
  
  <p>So I came up with the following:</p>
  
  <pre><code>public class DashFormatter : IFormatProvider, ICustomFormatter
  {
    public object GetFormat(Type formatType)
    {
      return this;
    }
  
    public string Format(string format, object arg, IFormatProvider formatProvider)
    {
      char[] chars = arg.ToString().ToCharArray();
      StringBuilder sb = new StringBuilder();
  
      for (int i = 0; i &lt; chars.Length; i++)
      {
        if (i &gt; 0 &amp;&amp; i % 4 == 0)
        {
          sb.Append('-');
        }
  
        sb.Append(chars[i]);
      }
  
      return sb.ToString();
    }
  }
  </code></pre>
  
  <p>and by using </p>
  
  <pre><code>string.Format(new DashFormatter(), "{0}", "F4194E7CC775F003");
  </code></pre>
  
  <p>I was able to solve the problem, however I was hoping there is a better/simpler way to do it? Perhaps some LINQ magic?</p>
  
  <p>Thanks.</p>