跳转至内容

substr

从给定字符串的给定偏移量开始返回该字符串的一部分(子字符串)。

基本用法

{"Smarty"|substr:2} # renders: arty
{"Smarty"|substr:2:3} # renders: art

参数

参数 类型 必需 说明
1 int 偏移量(以 0 为基准,可为负数)
2 int 返回的子字符串的长度(不限或省略)

示例

当与负偏移量一起使用时,子字符串从字符串末尾开始的 n 个字符处向后计数。

{"Smarty"|substr:-2} # renders: ty
{"Smarty"|substr:-2:1} # renders: t