title: IndexOf and ordinal string comparisons
body: <p>My problem is that <a href="http://msdn.microsoft.com/en-us/library/k8b1470s%28v=vs.110%29.aspx" rel="nofollow">String.IndexOf</a> returns <code>-1</code>. I would expect it to return <code>0</code>.</p>
  
  <p>The parameters:</p>
  
  <p><code>text</code> = <code>C:\\Users\\User\\Desktop\\Sync\\̼</code> (note the <a href="http://unicode-table.com/en/033C/" rel="nofollow">Combining Seagull Below</a> character)</p>
  
  <p><code>stringToTrim</code> = <code>C:\\Users\\User\\Desktop\\Sync\\</code></p>
  
  <p>When I check for the index, using <code>int index = text.IndexOf(stringToTrim);</code>, the value of <code>index</code> is <code>-1</code>. I found that using an ordinal string comparison solved this problem of mine:</p>
  
  <pre><code>int index = text.IndexOf(stringToTrim, StringComparison.Ordinal);
  </code></pre>
  
  <p>Reading online, a lot of Unicode characters (like <a href="http://unicode-table.com/en/search/?q=U%2B00B5" rel="nofollow">U+00B5</a> and <a href="http://unicode-table.com/en/search/?q=U%2B03BC" rel="nofollow">U+03BC</a>) map to the same symbol, so it would be a good idea to expand on this and normalize both strings:</p>
  
  <pre><code>int index = text.Normalize(NormalizationForm.FormKD).IndexOf(stringToTrim.Normalize(NormalizationForm.FormKD), StringComparison.Ordinal);
  </code></pre>
  
  <p>Is this the correct approach to check at what index one string contains all sequential characters of another string? So the idea is, you normalize when you want to check that symbols are a match, but you don't normalize when you want to check characters by their encoded values (allow duplicate symbols, therefore)? Also, could someone please explain why <code>int index = text.IndexOf(stringToTrim);</code> did not find a match at the start of the string? In other words, what is it actually doing under the covers? I would have expected it to start searching characters from the beginning of the string to the end of the string.</p>