title: Translating C++'s sprintf format string to C#'s string.Format
body: <p>I found the following C++ code (comments added myself):</p>
  
  <pre><code>// frame_name is a char array
  // prefix is std::string
  // k is a for loop counter
  // frames is a std::vector string
  sprintf(frameName, "%s_%0*s.bmp", prefix.c_str(), k, frames[k].c_str());
  </code></pre>
  
  <p>I then try to translate it to C#</p>
  
  <pre><code>// prefix is string
  // k is a for loop counter
  // frames is List&lt;string&gt;
  string frameName = string.Format("{0}_(what goes in here?).bmp", prefix, k, frames[k]);
  </code></pre>
  
  <p>Basically, what would be the C# equivalent of the C++ format string "%s_%0*s.bmp"?</p>
  
  <p>Edit, @Mark Byers:</p>
  
  <p>I've tried your code and made a little test program:</p>
  
  <pre><code>static void Main(string[] args)
  {
      List&lt;string&gt; frames = new List&lt;string&gt;();
      frames.Add("blah");
      frames.Add("cool");
      frames.Add("fsdt");
  
      string prefix = "prefix";
      int n = 2;
      int k = 0;
      string frameName = string.Format("{0}_{1}.bmp", prefix, frames[k].PadLeft(n, '0'));
      Console.WriteLine(frameName); // outputs prefix_blah.bmp, should output prefix_00blah.bmp
      Console.ReadLine();
   }
  </code></pre>
  
  <p>It's not padding for some reason.</p>
  
  <p>Edit: Got it working; won't pad if n = 2.</p>