gilo/fn/fn.go
2021-03-24 15:52:35 -04:00

23 lines
273 B
Go

package fn
import "strings"
func TruncateString(s string, length int) string {
if length < 1 {
return ""
}
var buf strings.Builder
count := 0
for _, char := range s {
if count == length {
break
}
buf.WriteRune(char)
count++
}
return buf.String()
}