Autor Beitrag
Calculon
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Mo 18.08.08 10:25 
Hallo,

ausblenden Delphi-Quelltext
1:
ShowMessage(Format('"%.6d"', [0]));					

führt zu diesem string:

Zitat:
---------------------------
"000000"
---------------------------
OK
---------------------------

Ich würde die leading zeros aber gerne dynamisch gestalten, also den markierten Wert in "Format('"%.6d"', [0]);" variabel machen. Geht das irgendwie?

Gruß
--

_________________
Hallo Mutti
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mo 18.08.08 11:01 
Variabel machen? Meinst du etwa so?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
  v: Integer;
begin
  v := 6;
  ShowMessage(Format('"%.' + IntToStr (v) + 'd"', [0]));
end;
Calculon Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Mo 18.08.08 11:10 
Genauso meinte ich das. Ich komme bei dieser C-Syntax Geschichte immer durcheinander. Vielen Dank!

Gruß
--

_________________
Hallo Mutti
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mo 18.08.08 13:35 
Wie ich neulich erstaunt in der Hilfe gefunden hab, geht das noch einfacher...


ausblenden Delphi-Quelltext
1:
2:
3:
4:
var stellen:integer;
begin
  stellen:= 10;
  ShowMessage(format('%.*d',[stellen,0]));


Delphi-Hilfe hat folgendes geschrieben:
Die Bezeichner für Index, Breite und Genauigkeit können direkt durch Angabe eines Strings mit dezimalen Ziffern (z.B. "%10d") oder indirekt mithilfe von Sternchen (z.B. "%*.*f") angegeben werden. Im letzteren Fall wird das Argument, das in der Argumentliste auf das Sternchen folgt (es muss sich dabei um einen Integerwert handeln), als tatsächlicher Wert verwendet.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mo 18.08.08 13:46 
user profile iconMartok hat folgendes geschrieben:
Wie ich neulich erstaunt in der Hilfe gefunden hab, geht das noch einfacher..

Wieder mal etwas gelernt. ;-) Danke für den Hinweis...