VC++
void StringTest(CString source, CStringArray& dest)
{
if(source.IsEmpty())
{
}
else
{
CString temp = source.Left(1);
CStringArray arr;
source = source.Mid(1);
StringTest(source,dest);
arr.Append(dest);
for(int i=0;i<dest.GetSize();i++)
{
CString data = dest.GetAt(i);
dest.SetAt(i,temp+data);
}
dest.Append(arr);
dest.Add(temp);
}
}
测试结果:
void CTestDlg::OnOK()
{
// TODO: Add extra validation here
CStringArray result;
CString str = "abc";
StringTest(str,result);
CString msg;
for(int j=0;j<result.GetSize();j++)
{
msg +=result.GetAt(j) + ",";
}
MessageBox("初始数据: "+ str + "\n所有组合: " +msg.Mid(0,msg.GetLength() - 1),"提示",MB_ICONINFORMATION|MB_OK);
CDialog::OnOK();
}