比如“你好啊”输出结果如图:有6种组合
代码:
static int count;
static void Combine(string str, string str2)
{
if (str == null)
return;
if (str == string.Empty)
{
Console.WriteLine(str2);
count++;
}
for (int i = 0; i < str.Length; i++)
{
Combine(str.Remove(i, 1), str2 + str[i].ToString());
}
}
调用方法:
string str2 = "";
Combine("abcd", str2);
输出结果: