title: Visual Studio C# - Can I extract a piece of text to a string variable?
body: <p>If I have the same string of text typed at numerous locations in my program, is there any way I can extract this to a string variable and, at each location where this was originally typed, have the code instead point to this one variable?</p>
  
  <p>For example, I have the following code:</p>
  
  <pre><code>if(File.Exists("C:\\whatever.txt"))
  {
      File.Delete("C:\\whatever.txt");
  }
  </code></pre>
  
  <p>Can I refactor that into this:</p>
  
  <pre><code>string s1 = "C:\\whatever.txt";
  
  if(File.Exists(s1))
  {
      File.Delete(s1);
  }
  </code></pre>
  
  <p>I know this is what I should have done initially, but lets say I'm getting the logic of a program sorted first, then I come along after to tidy up my code, are there any shortcuts in Visual Studio to allow me to do this or would I need to do so manually?</p>
  
  <p>Thanks</p>