这个方法也行
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ClipBrd;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
function GetAllSubSet(S: String;
StrLst: TStrings): Integer;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
ts: TStrings;
ct: Integer;
begin
ts := TStringList.Create;
ct := GetAllSubSet(Edit1.Text, ts);
ts.Insert(0, 'Count: ' + IntToStr(ct));
ts.Insert(0, '');
Clipboard.AsText := ts.Text;
ShowMessage(ts.Text);
ts.Free;
end;
function TForm1.GetAllSubSet(S: String;
StrLst: TStrings): Integer;
var
m: array[1..500] of Integer;
ts: String;
ns: String;
i, len: Integer;
begin
Result := 0;
if Length(S) = 0 then
Exit;
//此处应检测字符串中的重复字符并进行删除
//可以采用集合进行运算
ts := S;
len := Length(ts);
ns := StringOfChar(#0, 500);
i := 1;
m := 1;
while (i > 1) or (m <= len)do
begin
ns := ts[m];
ns[i+1] := #0;
StrLst.Add(PChar(ns));
if m < len then
begin
i := i + 1;
m := m[i-1]+1;
end
else
begin
i := i - 1;
m := m + 1;
end;
end;
Result := StrLst.Count;
end;
end.