if Chaine = EmptyStr then Exit;
procedure CompteCaracteresMots(Chaine: String; ListBox: TListBox); var Mot: String; begin if Chaine = EmptyStr then Exit; ListBox.Clear; Chaine := Trim(Chaine); Chaine := Chaine + ' '; // pour lire le dernier mot repeat Mot := Copy(Chaine, 1, Pos(' ', Chaine) -1); ListBox.Items.Add(IntToStr(Length(Mot))); Delete(Chaine, 1, Length(Mot)); Chaine := TrimLeft(Chaine); until Length(Chaine) = 0; end;
ListBox1.Items.Add(IntToStr(Edit1.GetTextLen));
procedure CompteCaracteresMots(Chaine: String; ListBox: TListBox); var i, PosEspace, NbreEspaces: Integer; Mot: String; begin ListBox.Clear; NbreEspaces := 0; for i := 1 to Length(Chaine) do if Copy(Chaine, i, 1) = ' ' then inc(NbreEspaces); // compte les espaces Chaine := Chaine + ' '; // pour lire le dernier mot for i := 0 to NbreEspaces do begin PosEspace := Pos(' ', Chaine); Mot := Copy(Chaine, 1, PosEspace); Chaine := Copy(Chaine, PosEspace + 1, Length(Chaine)); if Mot <> ' ' then ListBox.Items.Add(IntToStr(Length(Mot) -1)); {prise en compte faute de saisie genre double espace, voire triple ou plus...} end; end;
procedure TForm1.Button1Click(Sender: TObject); begin CompteCaracteresMots(Edit1.Text, ListBox1); end;
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionprocedure CompteCaracteresMots(Chaine: String; ListBox: TListBox); var Mot: String; begin ListBox.Clear; Chaine := Trim(Chaine); Chaine := Chaine + ' '; // pour lire le dernier mot repeat Mot := Copy(Chaine, 1, Pos(' ', Chaine) -1); ListBox.Items.Add(IntToStr(Length(Mot))); Delete(Chaine, 1, Length(Mot)); Chaine := TrimLeft(Chaine); until Length(Chaine) = 0; end;