Autor Beitrag
Cix6
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 60

Windows XP
Delphi 4 Standard, Delphi 7 PE, Delphi 2005 PE
BeitragVerfasst: Mo 10.04.06 10:20 
Hi,


ich möchte 2 Strings miteinander vergleichen und nur die Unterschiede ausgeben, ist das möglich?

Cix6
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 10.04.06 10:48 
Moin!

user profile iconCix6 hat folgendes geschrieben:
ich möchte 2 Strings miteinander vergleichen und nur die Unterschiede ausgeben, ist das möglich?

Ja! ;) (sorry, den konnte ich mir nicht verkneifen)

Geh die Strings zeichenweise durch (S[1] ist das 1. Zeichen im String S) und wenn die beiden Zeichen ungleich sind, kannste was damit tun.

Hmm... ziemlich viele Fragen und nur sehr wenig Eigeninitiative... wie wäre es zur Abwechslung mal mit einem bischen Code von dir, hm? :|

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 10.04.06 10:59 
user profile iconCix6 hat folgendes geschrieben:
hab gar keine ansätze!

Das ist aber der falsche Ansatz, um etwas zu programmieren. :wink:
Du musst dir erstmal überlegen, ab wann sich Strings unterscheiden. Wenn diese unterschiedlich lang sind, wird es schon problematisch. Dann sind sie eindeutig nicht gleich, aber der eine könnte im anderen enthalten sein.
Sind die Strings immer gleich lang? Dann kann die Zeichen, wie in einem Array vergleichen. Start und Ende der Unterschiede kann man dann protokollieren. Kann es mehrere Untscheide geben?
Du siehst, da ist erstmal einiges an Voraussetzungen zu schaffen, bevor der Vergleich überhaupt beginnen kann.

Moderiert von user profile iconraziel: Beitrag aus doppeltem Topic eingefügt.
Cix6 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 60

Windows XP
Delphi 4 Standard, Delphi 7 PE, Delphi 2005 PE
BeitragVerfasst: Mo 10.04.06 11:34 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
var
  d1, d2, d3: TStringlist;

  i: integer;
begin
   memo3.Text := '';

  d1 := TStringlist.create;
  d2 := TStringlist.create;
  d3 := TStringlist.create;
  d1.Text := memo1.Text;
  d2.text := memo2.Text;
  d3.text := memo3.text;


  for i := 0 to d2.count - 1 do
    if (d1.indexof(d2[i]) < 0and (trim(d2[i]) <> '')
     and (d3.indexof(d2[i]) < 0)
      then d3.add(d2[i]);
  memo3.text := d3.text;
  d3.free;
  d2.free;
  d1.free;
 end;
geht das noch besser?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 10.04.06 12:16 
Moin!

Ja, probier das mal so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var    
  i: Integer;    
begin    
  Memo3.Clear;  
  for i := 0 to Memo2.Lines.Count -1 do    
    if (Trim(Memo2.Lines.Strings[i]) <> ''then
      if (Memo1.Lines.IndexOf(Memo2.Lines.Strings[i]) = -1and     
         (Memo3.Lines.IndexOf(Memo2.Lines.Strings[i]) = -1then  
        Memo3.Lines.Add(Memo2.Lines.Strings[i]);  
end;

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.