title: How do I read and write smart quotes (and other silly characters) in C#
body: <p>I'm writing a program that reads all the text in a file into a string, loops over that string looking at the characters, and then appends the characters back to another string using a Stringbuilder. The issue I'm having is when it's written back out, the special characters such as <code>“</code> and <code>”</code> , come out looking like <code>ï¿½</code> characters instead. I don't need to do a conversion, I just want it written back out the way I read it in: </p>
  
  <pre><code>    StringBuilder sb = new StringBuilder();
      string text = File.ReadAllText(filePath);
      for (int i = 0; i &lt; text.Length; ++i) {
          if (text[i] != '{') {  // looking for opening curly brace
              sb.Append(text[i]);
              continue;
          }
          // Do stuff
      }
      File.WriteAllText(destinationFile, sb.ToString());
  </code></pre>
  
  <p>I tried using different Encodings (UTF-8, UTF-16, ASCII), but then it just came out even worse; I started getting question mark symbols and Chinese characters (yes, a bit of a shotgun approach, but I was just experimenting).
  I did read this article: <a href="http://www.joelonsoftware.com/articles/Unicode.html" rel="noreferrer">http://www.joelonsoftware.com/articles/Unicode.html</a>
  ...but it didn't really explain why I was seeing what I saw, unless in C#, the reader starts cutting off bits when it hits weird characters like that. Thanks in advance for any help!</p>