一. 字符串
函数的声明:
function Format(const Format: string; const Args: array of const): string; overload;
Format参数是一个格式字符串,用于格式化Args里面的值的。Args是一个变体数组,即它里面可以有多个参数,而且每个参数可以不同。
Args的格式为:”%” [index “:”] [“-“] [width] [“.” prec] type
格式名称 | explain | example |
---|
[index “:”] | Args第几个参数 | Format(“this is %1:d %0:d”,12,13);结果:this is 13 12 |
“-“ | 参数向左齐,和[width]合在一起 | Format(“this is %-4d,”,12);结果:this is 12 , |
width | 格式化得值占得宽度 | |
“.”prec | 指定精度 | Format(‘this is %.7f’,1.1234]);结果:this is 1.1234000 |
type | 如下表的含义 | |
Type | explain | example |
---|
d | 十进制的数,int类型 | |
u | 无符号的十进制数,2^32-负数的绝对值 | Format(“%u”,-2);结果:4294967294 |
f | 浮点数 | |
e | 科学表示法 | Format(“%e”,-2.22);结果:-2.2200000E+000 |
g | 将浮点值中的多余数去掉 | Format(“%g”,02.000);结果:2.2 |
n | 将浮点型转化为号码形式 | Format(“%n”,4552.2176),结果:4,522.22 |
P | 将指针类型的值返回 | Format(“%P”,P),结果:0012F548 |
m | 将浮点数格式化钱币型 | Format(“%m”,9552.21),结果:¥9,552.21 |
s | 字符串 | |
X | 将整形以十六进制返回 | Format(“%X”,15),结果:F |
x | 将整形以十六进制返回 | Format(“%x”,15),结果:f |