var Ts:tstringlist; s:string; i:integer; compt:integer; begin s:=Memo1.text; ts:=tstringlist.Create; s:=stringreplace(s,' ',#13,[rfReplaceAll]); s:=stringreplace(s,#13#10,'',[rfReplaceAll]); ts.SetText(pchar(s)); s:=''; ts.Sort; compt:=1; for i:=0 to ts.Count-2 do begin if ts[i]<>ts[i+1] then begin s:=s+ts[i]+' apparaît '+inttostr(compt)+' fois'+#13#10; compt:=1; end else inc(compt); end; if ts[ts.Count-1]<>ts[ts.Count-compt-1] then s:=s+ts[ts.Count-1]+' apparaît '+inttostr(compt)+' fois'+#13#10; Memo2.text:=s; ts.Free; end;
var Ts:tstringlist; s:string; i:integer; compt:integer; begin s:=Memo1.text; ts:=tstringlist.Create; s:=stringreplace(s,' ',#13,[rfReplaceAll]); s:=stringreplace(s,#13#10,'',[rfReplaceAll]); ts.SetText(pchar(s)); s:=''; ts.Sort; compt:=1; for i:=0 to ts.Count-2 do begin if ts[i]<>ts[i+1] then begin s:=s+ts[i]+' apparaît '+inttostr(compt)+' fois'+#13#10; compt:=1; end else inc(compt); end; if ((ts.Count-compt-1)>=0) and (ts[ts.Count-1]<>ts[ts.Count-compt-1]) then s:=s+ts[ts.Count-1]+' apparaît '+inttostr(compt)+' fois'; if ts[ts.Count-1]=ts[0] then s:=s+ts[ts.Count-1]+' apparaît '+inttostr(ts.count)+' fois'; Memo2.text:=s; ts.Free; end;
if Memo1.text<>'' then begin // ici le code-source end;
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questions:=stringreplace(s,' ',#13,[rfReplaceAll]);
s:=stringreplace(s,#32#32,#13,[rfReplaceAll]);ça revient au même et au moins pas de risque d'erreur...