共找到3條詞條名為truncate的結果 展開

truncate

計算機函數

truncate指的是一種語言函數。

C語言函數


相關函數:open,ftruncate
表頭文件:#include
定義函數:int truncate(const char*path,off_tlength);
函數說明:truncate()會將參數path指定的文件大小改為參數length指定的大小。如果原來的文件大小比參數length大,則超過的部分會被刪除
返回值:執行成功則返回0,失敗返回-1,錯誤原因存於errno
錯誤代碼:EACCESS參數path所指定的文件無法存取
EROFS欲寫入的文件存在於只讀文件系統內
EFAULT參數path指針超出可存取空間
EINVAL參數path包含不合法字元
ENAMETOOLONG參數path太長
ENOTDIR參數path路徑並非一目錄
EISDIR參數path指向一目錄
ETXTBUSY參數path所指的文件為共享程序,而且正被執行中
ELOOP參數path有過多符號連接問題
EIOI/O存取錯誤

資料庫操作


使用方法:
truncate table table_name;
操作特性:
truncate只刪除表中的所有數據,不刪除表的結構;
truncate使ddl操作立即生效,原數據不放到rollback segment中,不能回滾,操作不觸發trigger;
truncate語句預設情況下將空間釋放到minextents個extent,除非使用reuse storage;
truncate會將高水線複位(回到最開始)。

截取字元串


smarty truncate截取
從字元串開始處截取某長度的字元。默認是80個。
你也可以指定第二個參數作為追加在截取字元串後面的文本字串。該追加字串被計算在截取長度中。
默認情況下,smarty會截取到一個詞的末尾。
如果你想要精確的截取多少個字元,把第三個參數改為"true"。
例截取:
index.php:
$smarty=new Smarty;
$smarty->assign('articleTitle','Two Sisters Reunite after Eighteen Years at Checkout Counter.');
$smarty->display('index.tpl');
index.tpl:
{$articleTitle}
{$articleTitle|truncate}
{$articleTitle|truncate:30}
{$articleTitle|truncate:30:""}
{$articleTitle|truncate:30:"---"}
{$articleTitle|truncate:30:"":true}
{$articleTitle|truncate:30:"...":true}
輸出結果:
Two Sisters Reunite after Eighteen Years at Checkout Counter.
Two Sisters Reunite after Eighteen Years at Checkout Counter.
Two Sisters Reunite after...
Two Sisters Reunite after
Two Sisters Reunite after---
Two Sisters Reunite after Eigh
Two Sisters Reunite after E...