Bonjour,
Pour un besoin spécifique j'écris dans le canvas d'un bitmap du texte.
J'ai besoin de forcer un retour chariot si le texte est trop long esthétiquement parlant a peux prêt au milieu de celui-ci en remplaçant un espace par un retour chariot.
J'ai fait ce code (qui fonctionne), mais pensez-vous que l'on puisse l'améliorer ou le rendre plus rapide si j'ai beaucoup de texte a traiter ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 procedure TForm1.Button1Click(Sender: TObject); begin Label1.Text := DecouperPhrase(Edit1.Text); end; function TForm1.DecouperPhrase(const AValue: string): string; const LIMIT = 16; var sTmp: string; iMid, iPos, iLen: integer; begin sTmp := AValue; iLen := sTmp.Length; if iLen > LIMIT then begin iMid := iLen div 2; iPos := PosEx(' ', sTmp, iMid); if iPos > iMid then sTmp[iPos] := #13; end; Result := sTmp; end;
Partager