PDA

View Full Version : Missing a formatted printf for leading zeros


SetupJuggler
11-25-2008, 04:02 AM
Hi,
I'm Using SUF 8.1.1006.0

I want to convert a number to a string specifying the with of the string and heaving leading zeros or spaces.
e.g. 1 => "001" or " 1".
I'm looking for a function, like the C printf("%03d", number) or printf("% 3d", number).

A String.Format() or NumberToString would be a nice feature.

If there is already a function to easy convert, please give me a hint and I appologize for inconvenience.

Udo

Ulrich
11-25-2008, 06:15 AM
I want to convert a number to a string specifying the with of the string and heaving leading zeros or spaces.
e.g. 1 => "001" or " 1".
I'm looking for a function, like the C printf("%03d", number) or printf("% 3d", number).
A String.Format() or NumberToString would be a nice feature.
If there is already a function to easy convert, please give me a hint and I appologize for inconvenience.

Hi Udo,

there are native Lua functions (http://www.lua.org/manual/5.0/manual.html#format) able to to this.

For example:
mystring = string.format("%03d", number);
hexa = string.format("%02X", number);

Ulrich

SetupJuggler
11-25-2008, 06:47 AM
Thanks a lot Ulrich.

Tried it, works fine.:)
A hint within string online help would be appreciated to solve my problem.