Using some code in python that outputs special combinations of string in order: How to do that on c#
def getOrderCombinations(me):
l = len(me)
looped = me+ me
for start in range(0, l):
for length in range(1, l):
print(looped[start:start+length])
which gives:
>>> getOrderCombinations("ABCD")
A
AB
ABC
B
BC
BCD
C
CD
CDA
D
DA
DAB
I was trying
public static string[] Combinations(string str)
{
if (str.Length == 1)
return new string[] { str };
char c = str[str.Length - 1];
//here I was planning to make recursion
string[] returnArray = Combinations(str.Substring(0, str.Length - 1));
// keep final string combinations
List<string> finalArray = new List<string>();
//how to loop correctly and avoid getting all combinations
foreach (string s in returnArray)
finalArray.Add(s);
finalArray.Add(c.ToString());
}
for string 'ABCD', output should be 'A', 'B', 'C', 'D', 'AB', 'BC', 'CD', 'DA', 'ABC', 'BCD', 'CDA', DAB'. Thus, the amount of possible substrings of string length n will always be n*(n-1).
How to do it on c#?