title: Check whether two comma separated strings are equal (for Content set)
body: <p>I have four string as listed below. Though they have different order of characters and different spacing after comma – they are considered to have <code>same business value</code>.</p>
  
  <ol>
  <li>How do I check that all the strings are same (according to the business scenario explained above) ?  I have following code but it fails in the case of space after comma.</li>
  <li>What is the better method (for this purpose) than <code>Enumerable.SequenceEqual</code>?</li>
  </ol>
  
  <p>Note: "A,B" will be considered same as "B,A,B,A,B"</p>
  
  <p>Note: I am using <code>Visual Studio 2010</code> with <code>.Net Framework 4</code> </p>
  
  <p><strong>CODE</strong></p>
  
  <pre><code>  string firstString = "A,B,C";
    string secondString = "C,A,B";
    string thirdString = "A,B, C";
    string fourthString = "C, A,B";
  
  
    //Set 1 Test
    List&lt;string&gt; firstList = new List&lt;string&gt;(firstString.Split(','));
    List&lt;string&gt; secondLsit = new List&lt;string&gt;(secondString.Split(','));
    bool isStringsSame = Enumerable.SequenceEqual(firstList.OrderBy(t =&gt; t), secondLsit.OrderBy(t =&gt; t));
    Console.WriteLine(isStringsSame);
  
  
    //Set 2 Test
    List&lt;string&gt; thirdList = new List&lt;string&gt;(thirdString.Split(','));
    List&lt;string&gt; fourthList = new List&lt;string&gt;(fourthString.Split(','));
    bool isOtherStringsSame = Enumerable.SequenceEqual(thirdList.OrderBy(t =&gt; t), fourthList.OrderBy(t =&gt; t));
    Console.WriteLine(isOtherStringsSame);
  
    Console.ReadLine();
  </code></pre>
  
  <p><strong>UPDATE</strong>:</p>
  
  <p>Use <code>OrdianlIgnoreCase</code> for ignoring case sensitvity   <a href="https://stackoverflow.com/questions/2667635/how-to-use-hashsetstring-contains-method-in-case-insensitive-mode">How to use HashSet&lt;string&gt;.Contains() method in case -insensitive mode?</a>  </p>
  
  <p><strong>REFERENCE</strong>:</p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/2586602/best-way-to-check-for-string-in-comma-delimited-list-with-net">Best way to check for string in comma-delimited list with .NET?</a></li>
  <li><a href="https://stackoverflow.com/questions/3669970/compare-two-listt-objects-for-equality-ignoring-order">Compare two List&lt;T&gt; objects for equality, ignoring order</a></li>
  <li><a href="https://stackoverflow.com/questions/4629650/why-does-the-ienumerablet-select-works-in-1-of-2-cases-can-not-be-inferred">Why does the IEnumerable&lt;T&gt;.Select() works in 1 of 2 cases ? Can not be inferred from usage</a></li>
  <li><a href="https://stackoverflow.com/questions/1124216/what-is-the-shortest-code-to-compare-two-comma-separated-strings-for-a-match">What is the shortest code to compare two comma-separated strings for a match?</a></li>
  <li><a href="https://stackoverflow.com/questions/9060354/split-a-separated-string-into-hierachy-using-c-sharp-and-linq?rq=1">Split a separated string into hierarchy using c# and linq</a></li>
  <li><a href="https://stackoverflow.com/questions/1285347/count-matching-characters-between-two-strings-using-linq?rq=1">Count matching characters between two strings using LINQ</a></li>
  <li><a href="https://stackoverflow.com/questions/1536925/usinq-linq-to-select-items-that-is-in-a-semi-comma-separated-string?rq=1">Usinq Linq to select items that is in a semi-comma separated string?</a></li>
  <li><a href="https://stackoverflow.com/questions/2162545/determine-whether-two-or-more-objects-in-a-list-are-equal-according-to-some-prop?rq=1">Determine whether two or more objects in a list are equal according to some property</a></li>
  </ol>