string format
Marielle Lange
rp011s7075 at blueyonder.co.uk
Sat Aug 27 19:25:32 EDT 2005
There was some discussion not long ago on how to add spaces such that
a string fills a given fixed length. I discovered today that it was
in fact possible to use the equivalent of the sprintf command found
in c:
format(baseString[,valuesList])
format("Hello world") -- returns "Hello world"
format("Hello\nworld") -- returns "Hello" on one line, "world" on next
format("%1.3e",865.3) -- returns 8.653e+02, scientific notation
format("%o in octal\n%x in hex.",myNumber,myNumber)
format("%45d",5) -- returns "5" preceded by 45 spaces
Also look for:
String:
%[charLength]s
The corresponding value is unchanged, except that if a charLength is
specified, if the string is shorter than the charLength, enough
leading spaces are added to make it charLength characters long. If
the length of the string is equal to or greater than the charLength,
it is unchanged. For example, the incantation %3s transforms "H" to
" H".
Best,
Marielle
More information about the use-livecode
mailing list