Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8901081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:15:38+00:00 2026-06-15T01:15:38+00:00

I have four string as listed below. Though they have different order of characters

  • 0

I have four string as listed below. Though they have different order of characters and different spacing after comma – they are considered to have same business value.

  1. 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.
  2. What is the better method (for this purpose) than Enumerable.SequenceEqual?

Note: “A,B” will be considered same as “B,A,B,A,B”

Note: I am using Visual Studio 2010 with .Net Framework 4

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<string> firstList = new List<string>(firstString.Split(','));
  List<string> secondLsit = new List<string>(secondString.Split(','));
  bool isStringsSame = Enumerable.SequenceEqual(firstList.OrderBy(t => t), secondLsit.OrderBy(t => t));
  Console.WriteLine(isStringsSame);


  //Set 2 Test
  List<string> thirdList = new List<string>(thirdString.Split(','));
  List<string> fourthList = new List<string>(fourthString.Split(','));
  bool isOtherStringsSame = Enumerable.SequenceEqual(thirdList.OrderBy(t => t), fourthList.OrderBy(t => t));
  Console.WriteLine(isOtherStringsSame);

  Console.ReadLine();

UPDATE:

Use OrdianlIgnoreCase for ignoring case sensitvity How to use HashSet<string>.Contains() method in case -insensitive mode?

REFERENCE:

  1. Best way to check for string in comma-delimited list with .NET?
  2. Compare two List<T> objects for equality, ignoring order
  3. Why does the IEnumerable<T>.Select() works in 1 of 2 cases ? Can not be inferred from usage
  4. What is the shortest code to compare two comma-separated strings for a match?
  5. Split a separated string into hierarchy using c# and linq
  6. Count matching characters between two strings using LINQ
  7. Usinq Linq to select items that is in a semi-comma separated string?
  8. Determine whether two or more objects in a list are equal according to some property
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:15:39+00:00Added an answer on June 15, 2026 at 1:15 am

    Would you consider A,B to be equal to B,A,B,A,B? If so, you should be using sets. If not, an ordered sequence is appropriate.

    EDIT: Now we know you actually want set equality:

    var set1 = new HashSet<string>(firstString.Split(',').Select(t => t.Trim()));
    bool setsEqual = set1.SetEquals(secondString.Split(',').Select(t => t.Trim()));
    

    If we weren’t after set equality…

    To ignore the spaces, you should just trim them. For example:

    var firstOrdered = firstString.Split(',')
                                  .Select(t => t.Trim())
                                  .OrderBy(t => t);
    var secondOrdered = secondString.Split(',')
                                    .Select(t => t.Trim())
                                    .OrderBy(t => t); 
    bool stringsAreEqual = firstOrdered.SequenceEqual(secondOrdered);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several java objects with four string properties as below: For e.g. say
I have four identical sliders of the same class mySliderClass but with different id
I have a DataGridView with four Columns and need to crate a multiline string
Suppose I have a string like this: one two three four five six seven
I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
I have four tables. Three of them are tables with one key and they
I have four types of strings, as shown below. The difference is that the
Possible Duplicate: C# string formatting and padding In my C# program, I have four
I have a four-byte string read from a binary file, which is supposed to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.