{'123456'|truncate:6:"...":true}
{'1234567'|truncate:6:"...":true}
{'12345678'|truncate:6:"...":true}
{'中中中'|truncate:6:"...":true}
{'中中中中'|truncate:6:"...":true}
{'中中中中中'|truncate:6:"...":true}
{'中中中中中中'|truncate:6:"...":true}
{'中中中中中中中'|truncate:6:"...":true}
效果
123456123...123...中中中中中中中中中中中中中中中中中中中中中...
测试结果是:
少=于指定的数字时,不处理,直接显示;
多于时,先计算附加的有几个,不足指定数时再从字符串那里截取补足,所以 数字 6 = 3个附加字符(...) + 3个截取字符;
英文/中文算一下,测试时使用utf-8保存的源代码