Solved

TStringList - Get the item with no pair

Posted on 2010-09-22
10
502 Views
Last Modified: 2012-06-27
I have a 2 TStringList;

TSTringList-1 with;
john
nick
jason
rose
ryan
xen

TSTringList-2 with;
john
nick
jason
ryan
xen

How could I get the item("rose") with no pair in both TStringList-1&2
var
nams,nums:TStringList;
i,e:integer;
begin
Nams := TStringList.Create;
Nams.add('john');
Nams.add('nick');
Nams.add('jason');
Nams.add('rose');
Nams.add('ryan');
Nams.add('xen');

Nums := TStringList.Create;
Nums.add('john');
Nums.add('nick');
Nums.add('jason');
Nums.add('ryan');
Nums.add('xen');


for i := 0 to Nams.Count - 1 do
begin
for e:= 0 to nums.Count -1 do
begin
//get "rose" or items with no pair value
//dont know here, my codes are not better
//if e<>i then Listbox3.Items.Add(?);
end;
end;

end;

Open in new window

0
Comment
Question by:systan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 19

Expert Comment

by:Barthax
ID: 33734628
To exit the for loops with the first, you could something like (warning: my Delphi is rusty):

var
found : Boolean;
orphan: string;
[[... etc.]]]

for i := 0 to Nams.Count - 1 do
begin
found := false;

for e:= 0 to nums.Count -1 do
begin
  if Nams[i] == nums[i] then
  begin
    found := true;
    break;
  end;
end;

if not found then
begin
return Nams[i];
end;
end;

0
 
LVL 14

Author Comment

by:systan
ID: 33734791
The psuedo code is not working.
0
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 250 total points
ID: 33734987
i don't it will be very fast using a TStringList


procedure TForm1.Button1Click(Sender: TObject);
var
  nams,nums, sx:TStringList;
  i,e:integer;
  temp: string;
begin
  Nams := TStringList.Create;
  try
    Nams.add('john');
    Nams.add('nick');
    Nams.add('jason');
    Nams.add('rose');
    Nams.add('ryan');
    Nams.add('xen');

    Nums := TStringList.Create;
    try
      Nums.add('john');
      Nums.add('nick');
      Nums.add('jason');
      Nums.add('ryan');
      Nums.add('xen');

      sx := TStringList.Create;
      try
        for i := 0 to Nams.Count - 1 do
        begin
          if Nums.IndexOf(Nams[I]) < 0 then
            sx.Add(Nams[I] + ' does not exist in Nums');
        end;
        for i := 0 to Nums.Count - 1 do
        begin
          if Nams.IndexOf(Nums[I]) < 0 then
            sx.Add(Nums[I] + ' does not exist in Nams');
        end;
        Memo1.Lines.AddStrings(sx);
      finally
        sx.Free;
      end;
    finally
      Nums.Free;
    end;
  finally
    Nams.Free;
  end;
end;

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 33735029
>>Barthax ... you forgot to switch from PHP to Delphi
Nams[i] == nums[i] // PHP coding

Nams[i] = nums[i] // Delphi coding

Welcome back to the delphi world of coding ;-)


0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 33735045
i forgot a word in my earlier comment
it was something that i try to avoid actually : the word "think"

>>i don't think it will be very fast using a TStringList
0
 
LVL 14

Author Closing Comment

by:systan
ID: 33735066
Geert?
Your rank reflects your skills.

Thanks
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 33735123
skills ?
I just upped my skills with some good comments i found :

// drunk, fix later

// at the time I wrote this, only god and I knew what the code was doing
// now only god knows

// repeat
//   church code ...
// until (JezusChristReturns);

// You got this far reading my code, and you still understand it ?
// The rest gets worse, get your aspirin ready !
// May the source be with you
0
 
LVL 14

Author Comment

by:systan
ID: 33735155
Oh, really forgot this kind of code; it's so simple.

       sx := TStringList.Create;
        for i := 0 to Nams.Count - 1 do
        begin
          if Nums.IndexOf(Nams[I]) < 0 then
            sx.Add(Nams[I]);
        end;


forgetfull ;_
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 33735188
on the oracle database:

select * from Nums
minus
select * from Nams

or vice versa

but this is delphi ... uguhuhuhu
0
 
LVL 19

Expert Comment

by:Barthax
ID: 33742503
Thanks to Geert for recognising my rustiness. ;)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 167
Convert MS Word document to a PDF file 9 114
update joined tables 2 62
Delphi TListView and TEdit (Select item and input into TEdit) 10 43
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question