巴克励步
发布于:2025-01-02
truncate 将字符串截短为指定的字符个数。如果指定的字符数量小于字符串的长度,则会在字符串末尾添加一个省略号(…) 并将此省略号计入字符个数中。
{{ "Ground control to Major Tom." | truncate: 20 }}
Ground control to...
truncate 还支持第二个可选参数,用于指定一个字符序列,此字符序列将被添加到截短字符串的后面。默认是省略号(…),但是你可以按照你的需要传递一个新的。truncate 的第一个参数设置为 13,是因为需要计入省略号的 3 个字符。{{ "Ground control to Major Tom." | truncate: 25, ", and so on" }}
Ground control, and so on
{{ "Ground control to Major Tom." | truncate: 20, "" }}
Ground control to Ma