Answer the question
In order to leave comments, you need to log in
Why doesn't the tStringList comparison work?
Hello.
I have two tStringList (MainBase, Domain)
The first contains mail, the second contains domains respectively.
I need to check each line in MainBase whether each domain from the list is present in the line, if yes, then add it to another stringlist, if not, to another stringlist.
Here is my code :
for i:=0 to MainBase.Count-1 do
begin
for j := 0 to Domains.Count-1 do
begin
if Pos(Domains[j], MainBase[i])>0 then
begin
NormalBase.Add(MainBase[i]);
end else begin
nNormalBase.Add(MainBase[i]);
end;
end;
end;
Answer the question
In order to leave comments, you need to log in
Actually, that's how you wrote the code. Since for each domain there is a case of NOT matching with any of the mail addresses, then each will fall into the "bad" list, and more than once. If you need to find a list of domains that does not correspond to NONE of the listed email addresses, then it is more logical, after compiling the "good" list, to calculate the "bad" one in the second pass by subtracting the set of "good" domains from the set of all domains.
Get a Boolean flag Found. Drop it before looping over Domains. In the loop, when the condition under test is met, add a line to NormalBase, check the flag and break the loop (break) - why twist further? After looping through Domains, check the box. If not set, there were no matches - add a line to nNormalBase.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question