title: C#: Inserting Variable into Text File
body: <p>Summary: I want to insert variables into a text file. I tried looking around, so to no avail. Perhaps I'm searching with the wrong key words. I know to insert variables into a string, it's simply:</p>
  
  <pre><code>string str1 = "hello {0}";
  string str2 = "world";
  string final = string.Format(str1, str2); //Output should be "hello world"
  </code></pre>
  
  <p>Following the same notion, I made a text file of str1, loaded the text file into a string variable, and repeated the above process.</p>
  
  <p>str1.txt:</p>
  
  <pre><code>hello {0}
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>string str1 = System.IO.File.ReadAllText(@"..\..\str1.txt"); //Should load the text file as a string
  string str2 = "world"
  string final = string.Format(str1, str2); //Output should be "hello world"
  </code></pre>
  
  <p>Now, I'm getting the 'Input string was not in a correct format' error when I call string.Format and I'm not too sure why.</p>
  
  <p>Edit: Guess I didn't provide enough information. Sorry! The textfile I'm trying to insert variables into is a textfile of a class with {0}, {1}, ... inserted at various points.</p>