title: How to properly escape this string
body: <p>I have a string which I am sending to an external print function.<br>
  I need to pad the string with backslashes so it prints properly.</p>
  
  <p>Specifically, I need a method which would accept this example input:<br>
  <code>This is a string\nwith a line break\ta tab\rand a carriage return.</code></p>
  
  <p>and output:<br>
  <code>This is a string\\nwith a line break\\ta tab\\rand a carriage return.</code></p>
  
  <p>Do I need to brute force <code>Replace</code> every possible escape character with it's backslashed equivalent?</p>
  
  <p>Tried:<br>
  <code>s.Replace("\\","\\\\")</code>
  Doesn't work because it's looking for a backslash literal.</p>
  
  <p><code>s.Replace("\n","\\n")</code> obviously works, but what I'm looking for is a generic method.</p>
  
  <p>Edit:
  <strong>Please don't suggest brute force methods, I understand it is no problem to implement such a method. My question was if there is a more universal approach.</strong></p>