Thursday, February 18, 2010

How to check whether one string is anagram of other in c#?

static bool CheckAnagramOfString(string inputString1, string inputString2)
{
char[] charArr1 = inputString1.ToCharArray();
char[] charArr2 = inputString2.ToCharArray();
//sort both of them in same order
Array.Sort(charArr1);
Array.Sort(charArr2);
inputString1 = new string(charArr1);
inputString2 = new string(charArr2);

if (inputString1.Equals(inputString2))
{
return true;
}
else
{
return false;
}

}

No comments:

Post a Comment