title: c# Change the format of a string
body: <h3>Edit:</h3>
  
  <p>Because of your responses I think I've asked the question wrong.</p>
  
  <p>It's not that my solution doesn't work or isn't very clean. I'm interested if there is a general way, how you can foramt a string. Like you can do it with a int or other data types.</p>
  
  <p>So I couldn't find one. But I hope there is one. </p>
  
  <p><sub>So that's the question I wanted to ask:</sub>
  <br/></p>
  
  <h2>Does C# provides a way to format strings, like it does for a int or other data types?</h2>
  
  <p>I'm looking for something like this:</p>
  
  <pre><code>myString.Format(myFormat);
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>myFormattedString = String.Format(myString, myFormat);
  </code></pre>
  
  <p>And if the answer is no, it's also ok. I just want to know it.  (And maybe someone else as well)</p>
  
  <p><br/></p>
  
  <hr>
  
  <p><sub>Original question:</sub>
  <br/><br/></p>
  
  <h2><del>What's the best way to change the format of a string?</del></h2>
  
  <p>So I have a string that looks like this:</p>
  
  <pre><code>"123456789012345678"
  </code></pre>
  
  <p>And now I want that:</p>
  
  <pre><code>"12.34.567890.12345678"
  </code></pre>
  
  <hr>
  
  <p>I'm using this, but I don't find it very clean:</p>
  
  <pre><code>private string FormatString(string myString)
  {
      return myString.Insert(2, ".").Insert(5, ".").Insert(12, ".");
  }
  </code></pre>
  
  <hr>
  
  <p>Things I've tried:</p>
  
  <pre><code>// Too long.
  private string FormatString(string myString)
  {
      return myString.Substring(0, 2)
           + "."
           + myString.Substring(2, 2)
           + "."
           + myString.Substring(4, 6)
           + "."
           + myString.Substring(10, 8);
  }
  
  // Convertion from string -&gt; long -&gt; string.
  private string FormatString(string myString)
  {
      return String.Format("{0:##'.'##'.'######'.'########}", long.Parse(myString));
  }
  </code></pre>
  
  <hr>
  
  <p>I'm looking for something like that:</p>
  
  <pre><code>private string FormatString(string myString)
  {
      return String.Format("{0:##'.'##'.'######'.'########}", myString);
  }
  </code></pre>