szukaj, znajdz, wyszukaj w pliku txt

0

Witajcie mam nadzieje ze mi pomozecie.

Pytanie brzmi jak w pliku ktory jest wczytany np w memo lub richedit znaleŹĆ
fragment textu np: ( bez korzystania z komponentu finddialog )

wczytywany plik do memo lub richedita zawiera tresc:

                      ala ma kota kot ma ale znalazlem dom

Chce znaleŹĆ wyraz "kot" lub "znalazlem" przy czym nie chce korzystac z komponentu finddialog.
I jak znajdzie wyraz niech np zamknie program (close()) lub showmessage

( dodatkowo dobrze by bylo gdy mi powiedzial w ktorej linijce znalazl wyraz i mogl np zaczac dalsze szukanie tego wyrazu od tej linijki poprzedniego znalezionego)

Serdeczne dzieki za odpowiedzi na pewno nie jest to skaplikowane, jednak mam z tym problem.

0

Jeśli jesteś spragniony wiedzy to powinieneś sam wyszukać to na google, 4p, torry.net, a pomoc tutaj jest ostatecznie. [diabel]

http://www.vbforums.com/archive/index.php/t-346503.html

http://groups.google.com/group/de.comp.lang.pascal.delphi/browse_thread/thread/c3096ae0c0b2e26d/f6a83ce753fad00f?lnk=st&q=delphi+findtext&rnum=7#f6a83ce753fad00f

<font size="6">SZUKAĆ SAMODZIELNIE!!!</span>

0

Dzieki wielkie tego mi trzeba.
Nie szukalem an google szukalem tutaj ale tyle tych postow jest ze nie sposob znaleŹĆ wolalem spytac i wiedzialem ze znajdzie sie ktos madry i mi da gotowa odpowiedz.
Jeszcze raz dzieki.

Pod spodem umieszcze ten kod by nie zginol dla innych: ( na wypadek gdyby adres strony przestal dzialac )

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Memo1: TMemo;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
CheckBox1: TCheckBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private Declarations }
public
{ Public Declarations }
end;

var
Form1: TForm1;
x: Integer;
find: Boolean = False;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
a: string;
begin
Memo1.Lines.Add('');
Memo1.Lines.Text := ' ' + Memo1.Lines.Text;
for i := 0 to Length(Memo1.Lines.Text) - Length(edit1.Text) do
begin
a := Copy(Memo1.Lines.Text, i, Length(edit1.Text));
if CheckBox1.Checked = True then
begin
if a = edit1.Text then
begin
find := True;
x := 2;
Memo1.Lines.Text := Copy(Memo1.Lines.Text, 2, Length(Memo1.Lines.Text) - 1);
Memo1.SetFocus;
Memo1.SelStart := i - 2;
Memo1.SelLength := Length(edit1.Text);
break;
end;
end
else
begin
if lowercase(a) = lowercase(edit1.Text) then
begin
Memo1.Lines.Text := Copy(Memo1.Lines.Text, 2, Length(Memo1.Lines.Text) - 1);
find := True;
x := 2;
Memo1.SetFocus;
Memo1.SelStart := i - 2;
Memo1.SelLength := Length(edit1.Text);
break;
end;
end;
end;
if find = False then ShowMessage('String Not FOund')
else
find := False;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
i: Integer;
a: string;
d: Integer;
begin
d := 0;
for i := 0 to Length(Memo1.Lines.Text) - Length(edit1.Text) do
begin
a := Copy(Memo1.Lines.Text, i, Length(edit1.Text));
if CheckBox1.Checked = True then
begin
if a = edit1.Text then
begin
d := d + 1;
if d = x then
begin
find := True;
x := x + 1;
Memo1.Lines.Text := Copy(Memo1.Lines.Text, 2, Length(Memo1.Lines.Text) - 1);
Memo1.SetFocus;
Memo1.SelStart := i - 1;
Memo1.SelLength := Length(edit1.Text);
break;
Memo1.Lines.Text := Copy(Memo1.Lines.Text, 2, Length(Memo1.Lines.Text) - 1);
end;
end;
end
else
begin
if lowercase(a) = lowercase(edit1.Text) then
begin
d := d + 1;
if d = x then
begin
find := True;
x := x + 1;
Memo1.Lines.Text := Copy(Memo1.Lines.Text, 2, Length(Memo1.Lines.Text) - 1);
Memo1.SetFocus;
Memo1.SelStart := i - 1;
Memo1.SelLength := Length(edit1.Text);
break;
Memo1.Lines.Text := Copy(Memo1.Lines.Text, 2, Length(Memo1.Lines.Text) - 1);
end;
end;
end;
end;
if find = False then ShowMessage('String not found')
else
find := False;
end;

0

Jesli ktos zna inne rozwiazania moze dopisac:-))

0

Jeśli wyszukiwanie ma być case-sensitive, czy nie prościej użyć PosEx ?
Zresztą nawet jak by nie miało być case-sensitive to łatwo taką funkcje samemu napisać, a w podanym przykładzie to same komplikacje widze, pewnie dlatego że nie ma wcięć i nic tam nie widać

1 użytkowników online, w tym zalogowanych: 0, gości: 1