func truncate(str string, length int) (truncated string) {
if length <= 0 {
return
}
if len(str) < length{
return str
}
for i, char := range str {
if i >= length {
break
}
truncated += string(char)
}
return
}
go truncate string
欢迎转载,注明出处:刘世明的博客 » go truncate string
最新评论