/// <summary>
/// 字符串是否存在于“指定升序数字数字组成的任意位数字中”
/// eg:
/// ASet=178 可以组成的任意位升序数字是:1、7、8、17、18、78、178
/// 若Aval是其中一个则返回true,否则返回的是false
/// </summary>
/// <param name="AVal">带判断的值</param>
/// <param name="ASet">升序的数字字符串</param>
function Check_IsAllInAscNumberSetByAnyBit(const AVal, ASet: string): boolean;
function Combin(mStrings: TStrings; mStr: string; mLen: Integer): Boolean;
procedure fCombin(mSubStr: string; mPath: string);
var
I: Integer;
S: string;
b: Boolean;
lst: TStringList;
begin
if Length(mPath) >= mLen then
begin
lst := TStringList.Create;
for i := 1 to Length(mPath) do
begin
lst.Add(mPath[i]);
end;
lst.Sort;
b := True;
for i := 0 to lst.Count - 1 do
begin
if lst[i] <> mPath[i+1] then
begin
b := False;
Break;
end;
end;
lst.free;
if b then
mStrings.Add(mPath);
end
else
for I := 1 to Length(mSubStr) do
begin
S := mSubStr;
Delete(S, I, 1);
fCombin(S, mPath + mSubStr[I]);
end;
end;
begin
Result := False;
if not Assigned(mStrings) then Exit;
mStrings.BeginUpdate;
try
mStrings.Clear;
fCombin(mStr, '');
finally
mStrings.EndUpdate;
end;
Result := True;
end;
var
i: Integer;
lst: TStringList;
begin
Result := False;
lst := TStringList.Create;
try
Combin(lst, ASet, Length(AVal));
for i := 0 to lst.Count - 1 do
begin
if AVal = lst[i] then
begin
Result := True;
Exit;
end;
end;
finally
lst.Free;
end;
end;
procedure TForm1.btn1Click(Sender: TObject);
begin
if Check_IsAllInAscNumberSetByAnyBit(edt1.Text, '178') then
Caption := 'OK'
else
Caption := 'Bad';
end;
转载于:https://my.oschina.net/u/582827/blog/322895