Autor Beitrag
sonic159
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 76

Windows XP
BDS 2006 Professional
BeitragVerfasst: Fr 27.10.06 14:22 
Hallo!

Ich will mit meinem Programm ein Wort in einem Text suchen, und
dann die ganze Zeile in der sich das Wort befindet durch ein anderes ersetzen!

MfG: sonic
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Fr 27.10.06 14:28 
na dann viel spass und noch mehr erfolg ;)

ich denke, du willst da nun auch den ein oder anderen tip zu haben, oder?

okay... lies deine datei in eine stringliste ein. dann kannst du auf jede einzelne zeile zugreifen und deren inhalt nach einer bestimmten zeichenkombination durchsuchen (z.B. mit Pos) und anschließend, so fern gefunden, diese zeile leicht ersetzen.

abschließend kannst du den text auch wieder in eine datei schreiben


noch ein paar Stichworte:
TStringList
LoadFromFile
SaveToFile
Pos


Viel Spass,
C.
sonic159 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 76

Windows XP
BDS 2006 Professional
BeitragVerfasst: Fr 27.10.06 14:31 
Das Finden und alles hab ich schon, aber ich weiß nicht wie ich die Zeile ersetzen soll...?!
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Fr 27.10.06 14:36 
wenn du es mit TStringList machst...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
  for i := 0 to sl.Count - 1 do begin
    if Pos(Substr, sl[i]) > 0 then
      sl[i] := MeinAlternativerNeuerstring;
  end;


Musst mal schauen, evt. musst du an deinen MeinAlternativerNeuerstring noch ein Zeilenumbruchzeichen ( #13#10 ) dranhängen
sonic159 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 76

Windows XP
BDS 2006 Professional
BeitragVerfasst: Fr 27.10.06 14:54 
Dein Code funktioniert!
Nun Tritt der Fehler IM programm auf NICHT im Compiler,
er lautet: "Listenindex überschreitet das Maximum (263)".

Was nun?
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Fr 27.10.06 15:03 
hmm... wie groß ist denn diese datei? evt. solltest du das auch anders anfangen, wenn die dateien zu groß sind ;)

schau dir vielleicht mal die abschnitte zu textdateien, read, write, openfile, closehandle

da ist auch ein gutes beispiel dabei, wenn ich mich nicht täusche.

kurze frage noch... wie lange sind denn die zeilen in deinen textdateien? und wie groß sind die dateien insgesamt?

C.
sonic159 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 76

Windows XP
BDS 2006 Professional
BeitragVerfasst: Fr 27.10.06 15:26 
Insgesamt: 5 bis 7KB
Eine Zeile ist etwa so lang:
##########################################################
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Fr 27.10.06 18:03 
Hallo,
user profile iconsonic159 hat folgendes geschrieben:
Insgesamt: 5 bis 7KB
Eine Zeile ist etwa so lang:
##########################################################
dürfte beides keine Probleme bei einer Stringlist verursachen.

Hast Du das -1 in Deinen Code eingebaut?
ausblenden Delphi-Quelltext
1:
for i := 0 to sl.Count - 1 do begin					
Der Index der Stringlist ist 0-basierend!

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )