title: c# fixed length string
body: <p>I need to generate a text line with a fixed lenght:</p>
  
  <p>What I have right now is:</p>
  
  <pre><code>StringBuilder _sb = new StringBuilder();
  
  _sb.Append(string.Format("{0,5}", "MM")); // serie to cancel
  _sb.Append(string.Format("{0,20}", "45444")); // folio to cancel
  _sb.Append(string.Format("{0,30}", "AC1122")); // account number (optional)
  </code></pre>
  
  <p>This works great because generates a fixed lenght string of 55 characters.</p>
  
  <p>The issue comes when for example the optional value is a empty string like:</p>
  
  <pre><code>StringBuilder _sb = new StringBuilder();
  
  _sb.Append(string.Format("{0,5}", "MM")); // serie to cancel
  _sb.Append(string.Format("{0,20}", "45444")); // folio to cancel
  _sb.Append(string.Format("{0,30}", "")); // account number (optional)
  </code></pre>
  
  <p>Having empty string inside the string.format then wont give a fixed length, and I still need to have a 30 chars length.</p>
  
  <p>Any clue is well appreciated!!</p>
  
  <p>Thanks</p>