De specificaties zijn te onzeker, maar dit zou ik er ongeveer van maken:
Delphi Code:
uses
Classes, SysUtils;
type
TStringsHelper = class helper for TStrings
function IsIntersection(const ADest: TStrings): Boolean; overload;
function IsIntersection(const ADest: string): Boolean; overload;
end;
implementation
{ TStringsHelper }
function TStringsHelper.IsIntersection(const ADest: TStrings): Boolean;
var
C: Integer;
I: Integer;
P: Boolean;
begin
P := False;
I := 0;
while (not P) and
(I < Count) do
if Pos('=', Strings[I]) > 1 then
P := True
else
Inc(I);
// Bovenstaande kun je natuurlijk ook herschrijven als: P := Pos('=', Text) > 0;
C := 0;
I := 0;
Result := False;
if P then
while (I < ADest.Count) do
begin
if IndexOfName(ADest.Names[I]) >= 0 then
Inc(C);
Inc(I);
end
else
while (I < ADest.Count) do
begin
if IndexOf(ADest[I]) >= 0 then
Inc(C);
Inc(I);
end;
Result := C = ADest.Count;
end;
function TStringsHelper.IsIntersection(const ADest: string): Boolean;
var
SL: TStringList;
begin
SL := TStringList.Create;
try
SL.Delimiter := ',';
SL.DelimitedText := ADest;
Result := IsIntersection(SL);
finally
SL.Free;
end;
end;
Bookmarks