String Comparison

Hey,

I want to compare String in order to see if they contain the same characters.

In this way the String “ABC” would be equal to “BAC” or “CAB”, etc.

I’am searching on System.String methods but I can’t find one to make this. Is it possible?

Thanks

So many comparisons!

Yet none that do what you want.

You could sort the characters in the string, then compare the results of the sorts.

You might convert the string to a char array, then apply something like found here:

Then compare those results, or convert back to string and compare resulting strings.

You can give weight-age to each character , like if you say A = 1, B = 2, C = 3
and then you want to check that is ABC and BCA or CAB are the same or not
simple add their weight-age, if the resultant sum is same on both side, then they have same Character, else they don’t have same character

ABC = 1+2+3 = 6
BAC = 2+1+3 = 6
CAB = 3+1+2 = 6,
all of them are having the same output, just because of the Weight-age.

First check they are the same size, if they are then use ToCharArray() on both, sort them, and use Enumerable.SequenceEqual