Autor Beitrag
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Sa 19.11.05 00:35 
Hallo Leute !
Bräuchte mal Tips zu einem Problem.
Erst mal ein bsp. was ich vorhabe.
Textdatei

Vorher

Erste Zeile
Zweite Zeile Text Suchwort Rest
Dritte Zeile

Danach

Erste Zeile
Zweite Zeile Text Suchwort Rest Zugefügt
Dritte Zeile

Also müsste Ich zuerst das Suchwort finden den Rest zwischenspeichern, dann den Rest bis zum Zeilenende löschen, hinten etwas anfügen und hinter dem Suchwort wieder einfügen.
Wie könnte man das jetzt am einfachsten lösen ?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.Button1Click(Sender: TObject);  
var  
 i:Integer;  
 Suche:String;  
begin  
  Suche:='Suchwort';  
   for i:=0 to RichEdit1.lines.count-1 do  
   if pos(Suche,RichEdit1.lines[i])>0 then ...
 end;  
end.
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: Sa 19.11.05 01:05 
Hallo,

wenn das Suchwort nur einmal und immer vorhanden ist:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
var x,z : Integer;
begin
  with RichEdit1 do
  begin
  x := pos('Suchwort',Text)+Length('Suchwort')+1;
  for z := x to Length(Text) do
    if (Text[z] = #13) or (Text[z] = #10) then
      begin
      SelStart := x-1;
      SelLength := z-x;
      SelText := '<b>'+SelText+'</b>';
      Break;
      end;
  end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Sa 19.11.05 09:04 
Und wieso nicht einfach so?
procedure TForm1.Button1Click(Sender: TObject);
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var  
 i : Integer;  
 Suche, 
 Zugefuegt : String;  

begin  
  Suche:='Suchwort';  
  Zugefuegt := 'Zugefügt';
  for i:=0 to RichEdit1.lines.count-1 do  
   if pos(Suche,RichEdit1.lines[i])>0 then 
     RichEdit1.Lines[i] := RichEdit1.Lines[i]+Zugefuegt;
end;

_________________
Na denn, dann. Bis dann, denn.
Littleboxer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 41

Windows 2000,

BeitragVerfasst: Sa 19.11.05 10:26 
Weil das Suchwort in deinem Fall im am Ende einer Zeile sein muss.
Blackheart666 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Sa 19.11.05 11:12 
Ich danke Euch für Eure Tips damit komm Ich schon weiter.
Wie oft das Suchwort vorkommt weiß Ich vorher auch nicht und ob überhaupt.
Lannes hat schon gesehen was Ich vorhab und zwar wollte Ich den Kommentar von Pas Dateien finden also // bei den anderen Kommentaren usw ist es kein Problem, da kann Ich es ja mit Stringreplace tun.
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Sa 19.11.05 11:30 
user profile iconLittleboxer hat folgendes geschrieben:
Weil das Suchwort in deinem Fall im am Ende einer Zeile sein muss.

Nein. Zu jeder Zeile, in der das Suchwort vorkommt, wird etwas hinzugefügt. Da steht nicht, das das am Ende der Zeile sein muss, aber vielleicht hab ich ja das Problem nicht verstanden.

_________________
Na denn, dann. Bis dann, denn.
Blackheart666 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Sa 19.11.05 11:45 
alzaimar - Du hast das schon Richtig verstanden und es klappt auch so, also das gesuchte Wort ist ja in meinem Fall // ist, und da ja der Kommentar bis zum Ende der Zeile gilt wollte Ich ja am Ende der Zeile zum bsp. </font> setzen.
Vielen Dank nochmal an Alle !