博客文章预览100字怎么做啊?
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
什么叫做预览100字?截断到100字?
取一篇文章的前100字
我在 https://github.com/golang/exp/blob/master/utf8string/string.go 基础上加了一个方法:
https://github.com/golang/exp/blob/master/utf8string/string.go
// 求子串 func Substring(str string, length int, suffix string) string { if length >= len(str) { return str } utf8Str := NewString(str) if length > utf8Str.RuneCount() { return str } return utf8Str.Slice(0, length) + suffix }
第一个参数是文章内容,第二个是长度,比如 100,第三个是是否有后缀,比如 ...
我在 `https://github.com/golang/exp/blob/master/utf8string/string.go` 基础上加了一个方法: ```golang // 求子串 func Substring(str string, length int, suffix string) string { if length >= len(str) { return str } utf8Str := NewString(str) if length > utf8Str.RuneCount() { return str } return utf8Str.Slice(0, length) + suffix } ``` 第一个参数是文章内容,第二个是长度,比如 100,第三个是是否有后缀,比如 ...
明白了.3Q
`单行代码`
什么叫做预览100字?截断到100字?
取一篇文章的前100字
我在
https://github.com/golang/exp/blob/master/utf8string/string.go
基础上加了一个方法:第一个参数是文章内容,第二个是长度,比如 100,第三个是是否有后缀,比如 ...
明白了.3Q