Tuesday, August 2, 2011

Find all possible combinations of a string



Using below function we can find all possible combinations of any string.

  static void Combination(string left, string right)
        {
            if (right.Length == 1)
            {
                Console.Write(left);
                Console.Write(right);
                Console.WriteLine();
                return;
            }
            else
            {
                for (var index = 0; index < right.Length; index++)
                {
                    Combination(left + right[index], right.Remove(index, 1));
                }
            }
        }

you can call above function like:

 Combination("", Console.ReadLine());

Compiled By: Rajesh Rolen

Share This!


No comments:

Powered By Blogger · Designed By Seo Blogger Templates