How do I go about getting a combination and variation of an array of strings? let's say A, B, C, D expected to get something like this, which able to compute out even AB and BA view as differents combination.
A
AB
AC
ABC
ABCD
ACBD
...
B
BA
BC
BCD
BADC
...
Edit:
currently what i try was like code below by using List, was thinking should i make another permutation(like set= abcd,bcda,cdab.....
) for my string set in order to get the full list?
string set = "abcd";
// Init list
List<string> subsets = new List<string>();
// Loop over individual elements
for (int i = 1; i < set.Length; i++)
{
subsets.Add(set[i - 1].ToString());
List<string> newSubsets = new List<string>();
// Loop over existing subsets
for (int j = 0; j < subsets.Count; j++)
{
string newSubset = subsets[j] + set[i];
newSubsets.Add(newSubset);
}
subsets.AddRange(newSubsets);
}
// Add in the last element
subsets.Add(set[set.Length - 1].ToString());
subsets.Sort();