Jak szukać w TstringList?

0

HELP!!!!!!
Może wiecie jak wyszukać jakiś tekst w TsTring list?
Potem zrobić listę z tymi które je zawierają?

jeśli to zrobicie to zapraszam na [browar]

[angel]

0

Nie pijam alkoholu. Poczytaj o IndexOf albo zrób pętle For I:=0 TO StringList.Count-1 If StringList.Strings[I]=Szukane Then Hello;

0

masz tu dla custom edit, jak trochę pokombinujesz to bez problemu przerobisz na to o co ci chodzi:

unit SearchUnit;

interface

uses StdCtrls, Dialogs, StrUtils, SysUtils;

function SearchEdit(EditControl: TCustomEdit; const SearchString: String;
Options: TFindOptions; FindFirst: Boolean = False): Boolean;

procedure ReplaceEdit(EditControl: TCustomEdit; Const FindText,ReplaceText:string;Options: TFindOptions);

implementation

{ SearchEdit scans the text of a TCustomEdit-derived component for a given
search string. The search starts at the current caret position in the
control unless FindFirst is true then the search starts at the beginning.
The Options parameter determines whether the search runs forward
(frDown) or backward from the caret position, whether or not the text
comparison is case sensitive, and whether the matching string must be a
whole word. If text is already selected in the control, the search starts
at the 'far end' of the selection (SelStart if searching backwards, SelEnd
if searching forwards). If a match is found, the control's text selection
is changed to select the found text and the function returns True. If no
match is found, the function returns False. }

function SearchEdit(EditControl: TCustomEdit; const SearchString: String;
Options: TFindOptions; FindFirst: Boolean = False): Boolean;
var
Buffer, P: PChar;
Size: Word;
SearchOptions: TStringSearchOptions;
begin
Result := False;
if (Length(SearchString) = 0) then Exit;
Size := EditControl.GetTextLen;
if (Size = 0) then Exit;
Buffer := StrAlloc(Size + 1);
try
SearchOptions := [];
if frDown in Options then
Include(SearchOptions, soDown);
if frMatchCase in Options then
Include(SearchOptions, soMatchCase);
if frWholeWord in Options then
Include(SearchOptions, soWholeWord);
EditControl.GetTextBuf(Buffer, Size + 1);
if FindFirst then
P := SearchBuf(Buffer, Size, 0, EditControl.SelLength,
SearchString, SearchOptions)
else
P := SearchBuf(Buffer, Size, EditControl.SelStart, EditControl.SelLength,
SearchString, SearchOptions);
if P nil then
begin
EditControl.SelStart := P - Buffer;
EditControl.SelLength := Length(SearchString);
Result := True;
end;
finally
StrDispose(Buffer);
end;
end;

procedure ReplaceEdit(EditControl: TCustomEdit; Const FindText,ReplaceText:string;Options: TFindOptions);
var
Found: Boolean;
begin
if AnsiCompareText(EditControl.SelText, FindText) = 0 then
EditControl.SelText := ReplaceText;
Found := SearchEdit(EditControl, FindText, Options);
while Found and (frReplaceAll in Options) do
begin
EditControl.SelText := ReplaceText;
Found := SearchEdit(EditControl, FindText, Options);
end;
if (not Found) and (frReplace in Options) then
ShowMessage(Format('Tekst "%s" nie został znaleziony', [FindText]));
end;

end.

0

Dzięki bardzo!!!
[paker]

0

Nie pijam alkoholu. Poczytaj o IndexOf albo zrób pętle For I:=0 TO StringList.Count-1 If StringList.Strings[I]=Szukane Then Hello;

Tego nie trzeba pisac samemu. Nazywa sie IndexOf

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