title: Detect special symbols in c#
body: <p>I'm working on a c# project in which some data contains characters which are not recognised by the encoding. 
  They are displayed like that:</p>
  
  <p>"Some text � with special � symbols in it".</p>
  
  <p>I have no control over the encoding process, also data come from files of various origins and various formats. 
  I want to be able to flag data that contains such characters as erroneous or incomplete. Right now I am able to detect them this way:</p>
  
  <pre><code>if(myString.Contains("�"))
  {
     //Do stuff
  }
  </code></pre>
  
  <p>While it does work, it doesn't feel quite right to use the weird symbol directly in the Contains function. Isn't there a cleaner way to do this ?</p>
  
  <p>EDIT:</p>
  
  <p>After checking back with the team responsible for reading the files, this is how they do it:</p>
  
  <pre><code>var sr = new StreamReader(filePath, true);
  var content = sr.ReadToEnd();
  </code></pre>
  
  <p>Passing <code>true</code> as a second parameter of StreamReader is supposed to detect the encoding from the file's BOM, and use it to read the content. It doesn't always work though, as some files don't bear that information, hence why their data is read incorrectly. </p>
  
  <p>We've made some tests and using <code>StreamReader(filePath, Encoding.Default)</code> instead appears to work for most if not all files we had issues with. Expectedly, files that were working before not longer work because they do not use the default encoding.</p>
  
  <p>So the best solution for us would be to do the following: read the file trying to detect its encoding, then if it wasn't successful read it again with the default encoding. </p>
  
  <p>The problem remains the same though: how do we check, after trying to detect the file's encoding, if data has been read incorrectly ?</p>