23 lines
273 B
Go
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()
|
|
} |