truncate(计算机语言函数)

truncate计算机语言函数

truncate 会将高水线复位(回到最开始)。函数说明:truncate()会将参数path指定的文件大小改为参数length指定的大小。从字符串开始处截取某长度的字符.默认是80个。你也可以指定第二个参数作为追加在截取字符串后面的文本字串.该追加字串被计算在截取长度中。

外文名

truncate

相关函数

open, ftruncate

表头文件

#include

使用方法

truncate table table_name

编程函数

相关函数:open, ftruncate[1]

表头文件:#include

定义函数:int truncate(const char *path, off_t length);

函数说明:truncate()会将参数path指定的文件大小改为参数length指定的大小。 如果原来的文件大小比参数length大,则超过的部分会被删除

返回值:执行成功则返回0, 失败返回-1, 错误原因存于errno

错误代码:EACCESS 参数path所指定的文件无法存取

EROFS 欲写入的文件存在于只读文件系统内

EFAULT 参数path指针超出可存取空间

EINVAL 参数path包含不合法字符

ENAMETOOLONG 参数path太长

ENOTDIR 参数path路径并非一目录

EISDIR 参数path指向一目录

ETXTBUSY 参数path所指的文件为共享程序,而且正被执行中

ELOOP 参数path有过多符号连接问题

EIO I/O存取错误

操作语句

使用方法

truncate table table_name;

操作特性

truncate 只删除表中的所有数据,不删除表的结构;

truncate 是ddl操作立即生效,原数据不放到rollback segment中,不能回滚,操作不触发trigger;

truncate 语句缺省情况下将空间释放到 minextents个 extent,除非使用reuse storage;

truncate 会将高水线复位(回到最开始)。

符串函数

smartytruncate截取

从字符串开始处截取某长度的字符.默认是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...

参考资料

1.C语言truncate()函数:改变文件大小·C语言中文网

关键词:truncate