<p>I have a string "1112224444' it is a telephone number. I want to format as 111-222-4444 before I store it in a file. It is on a datarecord and I would prefer to be able to do this without assigning a new variable.</p>

<p>I was thinking:</p>

<pre><code>String.Format("{0:###-###-####}", i["MyPhone"].ToString() );
</code></pre>

<p>but that does not seem to do the trick.</p>

<p>** UPDATE **</p>

<p>Ok. I went with this solution</p>

<pre><code>Convert.ToInt64(i["Customer Phone"]).ToString("###-###-#### ####")
</code></pre>

<p>Now its gets messed up when the extension is less than 4 digits. It will fill in the numbers from the right. so</p>

<pre><code>1112224444 333  becomes

11-221-244 3334
</code></pre>

<p>Any ideas?</p>

As far as I know you can't do this with string.Format ... you would have to handle this yourself.  You could just strip out all non-numeric characters and then do something like:
```
```
string.Format("({0}) {1}-{2}",
     phoneNumber.Substring(0, 3),
     phoneNumber.Substring(3, 3),
     phoneNumber.Substring(6));
```
```
This assumes the data has been entered correctly, which you could use regular expressions to validate.