一. 字符串
函數的聲明:
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 |