Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Zahlenformatierung 00001 , 00002 (https://www.delphipraxis.net/26424-zahlenformatierung-00001-00002-a.html)

bundy 23. Jul 2004 16:25


Zahlenformatierung 00001 , 00002
 
Hallo alle zusammen.

Ich hab da mal eine Frage:

Wie kann ich einen string erzeugen der folgendermassen aussieht.

V00001.txt
V00002.txt
V00003.txt
.
.
V01358.txt
usw

Kann mann irgendwie einen Zahl Formatieren das sie als Basis 00001 hat ? :gruebel:

rantanplan99 23. Jul 2004 16:30

Re: Zahlenformatierung 00001 , 00002
 
siehe funktion format in der online help

Duffy 23. Jul 2004 16:31

Re: Zahlenformatierung 00001 , 00002
 
Hallo Bundy,
so sollte es gehen
Delphi-Quellcode:
NewFileName := Format('V%0.5d.txt', [Zahl]) ;
bye
Claus

xineohp 23. Jul 2004 16:32

Re: Zahlenformatierung 00001 , 00002
 
moin,

praktisch ist auch die Funktion FormatFloat, die meines Erachtens einfacher (zumindest intuitiver) zu bedienen ist.

bundy 23. Jul 2004 17:19

Re: Zahlenformatierung 00001 , 00002
 
Danke es funzt :dancer: :hello: :dancer: :hello: :dancer:

bigg 23. Jul 2004 17:53

Re: Zahlenformatierung 00001 , 00002
 
hi,

hier eine simple Methode es ohne Format zu lösen.
Man könnte ja mal mit GetTickCount messen, welche Methode schneller ist.


Code:

procedure TForm1.Button1Click(Sender: TObject);

const Max = 1000;
const Name = 'v';
var i, j, LMax, Ls: Integer;
var s, Text: string;

begin
LMax := Length(IntToStr(Max));

if LMax > 1 then
begin for i := 1 to Max do
begin
s := IntToStr(i); {Die Zahl in einen Integer umwandelm}
Ls := LMax - Length(s); {Die Länge der Zahl ermitteln minus der Gesamtlänge von Max}

if (Ls < LMax) and (Ls > 0) then
for j := 1 to Ls do s := '0' + s; {mögliche Nullen dranhängen}

s := Name + s; {Namen dranhängen}
ListBox1.Items.Add(s); {Die Zahlen in die Liste eintragen}
end;


end;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 00:10 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz