字符串操作之格式化
字符串操作之格式化
函數(shù) function Format(const Format: string; const Args: array of const): string; ?需引用 SysUtils.pas
功能 返回按指定方式格式化一個(gè)數(shù)組常量的字符形式
說(shuō)明 這個(gè)函數(shù)是我在Delphi中用得最多的函數(shù),現(xiàn)在就列舉幾個(gè)例子給你個(gè)直觀的理解
"%" [索引 ":"] ["-"] [寬度] ["." 摘要] 類型
Format('x=%d', [12]); //'x=12' //最普通
Format('x=%3d', [12]); //'x= 12' //指定寬度
Format('x=%f', [12.0]); //'x=12.00' //浮點(diǎn)數(shù)
Format('x=%.3f', [12.0]); //'x=12.000' //指定小數(shù)
Format('x=%.*f', [5, 12.0]); //'x=12.00000' //動(dòng)態(tài)配置
Format('x=%.5d', [12]); //'x=00012' //前面補(bǔ)充0
Format('x=%.5x', [12]); //'x=0000C' //十六進(jìn)制
Format('x=%1:d%0:d', [12, 13]); //'x=1312' //使用索引
Format('x=%p', [nil]); //'x=00000000' //指針
Format('x=%1.1e', [12.0]); //'x=1.2E+001' //科學(xué)記數(shù)法
Format('x=%%', []); //'x=%' //得到"%"
S := Format('%s%d', [S, I]); //S := S + StrToInt(I); //連接字符串
轉(zhuǎn)載于:https://www.cnblogs.com/m0488/p/9555951.html
總結(jié)
- 上一篇: Difference Between I
- 下一篇: k8s入门