add stringx.FirstN (#914)

This commit is contained in:
Kevin Wan
2021-08-15 23:02:48 +08:00
committed by GitHub
parent a21ff71373
commit f2612db4b1
3 changed files with 60 additions and 4 deletions

View File

@@ -40,6 +40,20 @@ func Filter(s string, filter func(r rune) bool) string {
return string(chars[:n])
}
// FirstN returns first n runes from s.
func FirstN(s string, n int) string {
var i int
for j := range s {
if i == n {
return s[:j]
}
i++
}
return s
}
// HasEmpty checks if there are empty strings in args.
func HasEmpty(args ...string) bool {
for _, arg := range args {