I need a way to check two strings to see if they have the same words in them but in different positions. I only need the number of words out of word, not the actual words. For example: string 1 is "this is an out of order test" and string 2 is "this is an order out of test" would return 1 as one word is out of order.
I've started with the following code:
public int OutOfOrder(string string1, string string2)
{
var search1 = string1.Split(' ');
var search2 = string2.Split(' ');
var OutOfOrder = 0;
for (int i = 0; i < search1.Count() - 1; i++)
{
if (search2.Contains(search1[i]))
{
for (int j=0; j < search2.Count()-1; j++)
{
if(search1[i] == search2[j] && i == j)
{
continue;
}
else if (search1[i] == search2[j] && i != j)
{
OutOfOrder++;
break;
}
}
}
}
return OutOfOrder;
}
However everything is out of order after the first one encountered and the number returned is not correct.