將字符串截短為指定的單詞個數(shù)。如果指定的單詞數(shù)量小于字符串中包含的單詞個數(shù),則會在字符串末尾添加一個省略號(…)。
輸入
{{ "Ground control to Major Tom." | truncatewords: 3 }}
輸出
Ground control to...
truncatewords
?還支持第二個可選參數(shù),用于指定一個字符序列,此字符序列將被添加到截短字符串的后面。默認是省略號(…),但是你可以按照你的需要傳遞一個新的。
輸入
{{ "Ground control to Major Tom." | truncatewords: 3, "--" }}
輸出
Ground control to--
如果你不希望在末尾添加省略號,可以將?truncatewords
?的第二個參數(shù)設置為空字符串:
輸入
{{ "Ground control to Major Tom." | truncatewords: 3, "" }}
輸出
Ground control to
? Copyright 2023 深圳藍曬科技有限公司. 粵ICP備2023054553號-1