Bacterius
Messages postés3792Date d'inscriptionsamedi 22 décembre 2007StatutMembreDernière intervention 3 juin 2016
-
17 févr. 2008 à 12:45
f0xi
Messages postés4205Date d'inscriptionsamedi 16 octobre 2004StatutModérateurDernière intervention12 mars 2022
-
17 févr. 2008 à 13:44
Bonjour, je voudrais juste savoir si une fonction est déja existante pour savoir si il y a 2 chaines d'un meme texte dans une liste de chaines (TStrings) et si possible détecter leur position, et sinon me donner quelques conseils pour créer cette fonction...
f0xi
Messages postés4205Date d'inscriptionsamedi 16 octobre 2004StatutModérateurDernière intervention12 mars 202235 17 févr. 2008 à 13:44
type
TIndexArray = array of integer;
function GetStrIndexs(const S: string; Strings: TStrings; var Count: integer; var Indexs: TIndexArray;
const MatchCase: boolean = true): boolean;
var N : integer;
begin
count := 0;
result:= false;
if Strings.Count <= 1 then
exit;
SetLength(Indexs, Strings.Count);
case MatchCase of
true : for N := 0 to Strings.Count-1 do
if CompareStr(S, Strings[N]) = 0 then
begin
Indexs[Count] := N;
Count := Count + 1;
end;
false : for N := 0 to Strings.Count-1 do
if CompareText(S, Strings[N]) = 0 then
begin
Indexs[Count] := N;
Count := Count + 1;
end;
end;
SetLength(Indexs, Count);
result := Count > 0;
end;
EXEMPLE :
procedure TForm1.Button1Click(Sender: TObject);
var Idxs : TIndexArray;
N,Cnt : integer;
begin
if GetStrIndexs(Edit1.Text, ListBox1.Items, Cnt, Idxs, false) then
begin
ListBox1.MultiSelect := true;
for N := 0 to ListBox1.Count-1 do
ListBox1.Selected[ N ] := false;
for N := 0 to Cnt-1 do
ListBox1.Selected[ Idxs[N] ] := true;
end;
end;