textfmt
textfmt |
Purpose
Create a formatted text from a string, a text or a number.
Synopsis
function textfmt(str:string, len:integer):text
function textfmt(txt:text, len:integer):text
function textfmt(i:integer, len:integer):text
function textfmt(i:integer, len:integer, flag:integer, base:integer):text
function textfmt(r:real, len:integer):text
function textfmt(r:real, len:integer, dec:integer):text
Arguments
str
|
String to be formatted
|
||||||
txt
|
Text to be formatted
|
||||||
i
|
Integer to be formatted
|
||||||
r
|
Real to be formatted
|
||||||
len
|
Reserved length (may be exceeded if given string is longer, in this case the string is always left justified).
|
||||||
flag
|
Bit encoded options:
|
||||||
base
|
Encoding base (between 2 and 36)
|
||||||
dec
|
Number of digits after the decimal point
|
Return value
Formatted text.
Example
The following:
writeln("text1", textfmt("text2",8), "text3") writeln("text1", textfmt("text2",-8), "text3") r:=789.123456 writeln(textfmt(r,0)," ", textfmt(r,4,2), textfmt(r,8,0))
produces this output:
text1 text2text3 text1text2 text3 789.123 789.12 789
Further information
1. If the resulting string is longer than the reserved space it is not cut but printed in its entirety, overflowing the reserved space to the right.
2. When processing an integer specifying a base, the provided value is treated as an unsigned integer if the base is negative.
Related topics
Module