Salut,
@dubois77
Je pense que ta fonction peut-être remplacé simplement comme ceci (pas testé)
function Mot(h:string; n:integer=1):variant;
var
T : TStringList;
begin
T := TStringList.Create;
try
T.Delimiter := ' ';
T.DelimitedText := h;
if (T.Count <> -1) and (n <= T.Count) then
Result := T.Strings[n-1]
else
Result := Format('Pas de mot en position %d',[n]);
finally
T.Free;
end;
end;
@Dioufthier
Que cherche tu as faire exactement remplacer une chaine '5 toto 6 papa' par '5,toto,6,papa'
(J'utilise ton exemple dubois77,il me plait bien )
alors utilise StringReplace exemple
Edit1.Text := StringReplace('5 toto 6 papa',' ',',',[rfReplaceAll]);
ou séparer '5,toto,6,papa' alors utilise les TStringList
Un exemple tout bête avec un bouton et un memo (pas testé)
procedure SepEdit(S: string; List: TStrings);
var
T : TStringList;
begin
T := TStringList.Create; //Création TStringList
try
T.Delimiter := ','; //Pas utile par défaut c'est déjà ','
T.DelimitedText := S; //Séparation du texte
List.Clear; //Efface le contenu précédent
List.AddStrings(T); //Mise en place du trie dans le TStrings ici Memo1.Lines
finally
T.Free; // Libération TStringList
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SepEdit('5,toto,6,papa',Memo1.Lines);
end;
J'espère t'avoir aidé
@+yanb