Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-01

format string - number padding

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

ik

Hello,

I'm trying to use the Format function to pad a number like so: 01
where the original value is "$1".

I tried to do the following:

writeln(Format('%02X', [$1]));
writeln(Format('%0:2X', [$1]));
writeln(Format('%:2X', [$1]));

All of them created the following output:
" 1"

What am I doing wrong ?

Thanks,
Ido

Reply by email

Sven Barth
"ik" wrote 17 lines
Hello, I'm trying to use the Format function to pad a number like so: 01 where the original value is "$1". I tried to do the following: writeln(Format('%02X', [$1])); writeln(Format('%0:2X', [$1])); writeln(Format('%:2X', [$1])); All of them created the following output: " 1" What am I doing wrong ?

You tried nearly everything except %.2X :)

See also the examples here:
http://www.freepascal.org/docs-html/rtl/sysutils/format.html

Regards,
Sven

Reply by email

Lubomír Čabla
to ik: I'm trying to use the Format function to pad a number like so: 01 where the original…
Try
writeln(Format('%.2x', [$1]));
ik wrote 27 lines
Hello, I'm trying to use the Format function to pad a number like so: 01 where the original value is "$1". I tried to do the following: writeln(Format('%02X', [$1])); writeln(Format('%0:2X', [$1])); writeln(Format('%:2X', [$1])); All of them created the following output: " 1" What am I doing wrong ? Thanks, Ido _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

ik
to Sven Barth: You tried nearly everything except %.2X :) See also the examples here:…
Sven Barth wrote 26 lines
Am 09.01.2012 12:08 schrieb "ik" : > > Hello, > > I'm trying to use the Format function to pad a number like so: > 01 > where the original value is "$1". > > I tried to do the following: > > writeln(Format('%02X', [$1])); > writeln(Format('%0:2X', [$1])); > writeln(Format('%:2X', [$1])); > > All of them created the following output: > " 1" > > What am I doing wrong ? You tried nearly everything except %.2X :) See also the examples here: http://www.freepascal.org/docs-html/rtl/sysutils/format.html

Thanks. It's a bit difference then C and few other languages :(

Show quoted text 7 lines
Regards, Sven _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email