strfmt
strfmt |
Purpose
Synopsis
function strfmt(str:string,len:integer):string
function strfmt(i:integer, len:integer):string
function strfmt(r:real, len:integer):string
function strfmt(r:real, len:integer, dec:integer):string
Arguments
str
|
String 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).
|
||||||
dec
|
Number of digits after the decimal point
|
Return value
Formatted string.
Example
The following:
writeln("text1", strfmt("text2",8), "text3") writeln("text1", strfmt("text2",-8), "text3") r:=789.123456 writeln(strfmt(r,0)," ", strfmt(r,4,2), strfmt(r,8,0))
produces this output:
text1 text2text3 text1text2 text3 789.123 789.12 789
Further information
1. This function creates a formatted string from a string or an integer or real number. It can be used at any place where strings may be used. Its most likely use is for generating printed output (in combination with
write and
writeln).
2. 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.
Related topics