Autor Beitrag
Cathleen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 26.11.06 16:55 
Hallo,

es ist bestimmt die leichteste Übung...

Wie kann ich doppelte Strings aus einer Stringliste entfernen? Gibt es bereits eine Funktion dafür?
Wenn nicht, muss ich es eben selber proggen. Wäre aber schön wenn es da schon was gibt von Delphi.

zum Verständnis:

Stringliste1: ('Hallo';'Welt';'Hallo');

Danach

Stringliste2: ('Hallo';'Welt');

Danke!

Cathleen
evilsoft.de
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 39

XP
Delphi 7
BeitragVerfasst: So 26.11.06 17:08 
ausblenden volle Höhe 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:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
program killdbllines;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Classes;

function exists(gibts:String; sl: TStringList):Boolean;
var
  i:integer;
begin
  Result := False;
  for i:=0 to sl.Count-1 do
  begin
    if sl.Strings[i] = gibts then
    begin
      Result := True;
      break;
    end;
  end;
end;

var
  sl, res: TStringList;
  i:Integer;
begin
  if ParamStr(1) <> '' then
  begin
    sl := TStringList.Create;
    res := TStringList.Create;
    sl.LoadFromFile(ParamStr(1));
    for i := 0 to sl.Count-1 do
    begin
      if not exists(sl.Strings[i], res) then
      begin
        res.Add(sl.Strings[i]);
      end;
      Write(IntToStr(i+1)+' of '+IntToStr(sl.Count));
    end;
    sl.Free;
    res.SaveToFile(ParamStr(1)+'.txt');
    res.Free;
    WriteLn('Done!');
    readln;
  end;
end.


geht zwar besser, aber das ist sehr leicht zu verstehen ;)
Cathleen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 26.11.06 17:16 
Hallo,

danke für deine schnelle Antwort.

Ist das dein ernst???? ;-)

Das ist ja soviel. Ich weiß das es bei PHP und Java bereits funktionen gibt die man benutzen kann.

Wenn das wirklich alles ist, dann ist mir Delphi unsympatisch.

Danke!

MFG
Cathleen
Bernhard Geyer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 721
Erhaltene Danke: 3



BeitragVerfasst: So 26.11.06 17:28 
user profile iconCathleen hat folgendes geschrieben:
Ist das dein ernst???? ;-)

Das ist ja soviel. Ich weiß das es bei PHP und Java bereits funktionen gibt die man benutzen kann.

Wenn das wirklich alles ist, dann ist mir Delphi unsympatisch.

Dann schau dir mal den Code an. Das ist ein komplettes Programm um aus Textdateien doppelte Zeilen zu löschen. Also mehr als Du eigentlich willst.

Schau dir doch einfach mal das Duplicates-Property von TStringList an.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mo 27.11.06 00:25 
Außerdem kann man die Funktion "exists" durch die "IndexOf"-Funktion der StringListe in eine Zeile fassen ;-)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Cathleen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Mo 27.11.06 22:53 
aaaaahh :idea:

Super, danke!

Gruß
Cathleen