Autor Beitrag
Hochhäusl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57



BeitragVerfasst: Sa 29.03.03 13:43 
Hi,

ich habe bereits folgenden Code:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.Button3Click(Sender: TObject);
var sl: TStringList;
  zeilennr: integer;
begin
  sl:=TStringList.Create;

  try
    sl.LoadFromFile('c:\beispiel.txt');
    for zeilennr:=0 to sl.Count-1 do begin
      if sl[zeilennr]='Zweite Zeile' then
        edit1.Text:=sl[zeilennr+1];
    end;
  finally
    sl.free;
  end;


Problem:
Ich hätte gerne, dass er nicht wie hier nach einer Zeile sucht und die nächste ([zeilenr+1]) nach edit1 ausgibt sondern wie oben eine Zeile sucht und alle folgenden Zeilen ( mit Zeilenumbruch) in ein Memo lädt bis z.B. ein ":" oder ";" kommt.


Hochhäusl
BungeeBug
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 901



BeitragVerfasst: Sa 29.03.03 14:28 
Hi ...
dann benutzt doch einfach das Memo dazu.
ausblenden Quelltext
1:
2:
 
Memo1.Lines.LoadFromFile(<Filename>);

und dann würd ich erste die Zeilen löschen die ich nicht haben will ...

MfG BungeeBug
Alibi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 458

Win2K SP3
Delphi 6 Ent
BeitragVerfasst: Sa 29.03.03 14:34 
Eine Textdatei über ein Memo laden um sowas zu machen, omg...

Man kann auch ganz wunderbar .Delete der TStringList aufrufen.
BungeeBug
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 901



BeitragVerfasst: Sa 29.03.03 20:05 
ja aber er wills ja eh in nen memo haben
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: Sa 29.03.03 22:29 
Weil's du bist ,extra für dich ;):
ausblenden volle Höhe 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:
procedure LoadText(const FileName, First, Last: String;
  const AStrings: TStrings);
var
  SL: TStringList;
  I: Integer;
  B: Boolean;
begin
  B := False;
  SL := TStringList.Create;
  with SL do begin
    try
      LoadFromFile(FileName);
      for I := 0 to Count - 1 do begin
        if  (not B)
        and (Pos(First, Strings[I]) > 0) then begin
          B := True;
          AStrings.Add(Copy(Strings[I], Pos(First, Strings[I]) + Length(First),
            Length(Strings[I])));
        end
        else begin
          if Pos(Last, Strings[I]) = 0 then
            AStrings.Add(Strings[I])
          else begin
            AStrings.Add(Copy(Strings[I], 1, Pos(Last, Strings[I]) - 1));
            Break;
          end;
        end;
      end;
    finally
      Free;
    end;
  end;
end;
Gruß wulfskin!

_________________
Manche antworten um ihren Beitragszähler zu erhöhen, andere um zu Helfen.
inselberg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 458



BeitragVerfasst: Sa 29.03.03 22:51 
also ich mach "sowas" immer wie folgt
ausblenden Quelltext
1:
2:
3:
4:
5:
stringlist.loadfromfile

p:=pos("das was ich suche", stringlist.text);

copy(stringlist.text,p,length(stringlist.text));

weil stringlist.delete ist ziemlich langsam ... will hoffen dass der "pseudo" code verständlich ist

Moderiert von user profile iconTino: Code-Tags hinzugefügt.
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: So 30.03.03 01:31 
inselberg hat folgendes geschrieben:
also ich mach "sowas" immer wie folgt

stringlist.loadfromfile

p:=pos("das was ich suche", stringlist.text);

copy(stringlist.text,p,length(stringlist.text));

weil stringlist.delete ist ziemlich langsam ...

will hoffen dass der "pseudo" code verständlich ist
Schau mal 20 cm weiter oben ;)

_________________
Manche antworten um ihren Beitragszähler zu erhöhen, andere um zu Helfen.
Hochhäusl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57



BeitragVerfasst: Di 01.04.03 18:31 
Hi,

danke für eure Antworten!
Ich habe den code ausprobiert und es klappt FAST.
Es werden die Zeilen bis zu einem bestimmten Zeichen kopiert
dies jedoch immer von der 1. Zeile an!