Skip to content

Instantly share code, notes, and snippets.

@nanmu42
Created Mar 8, 2021
Embed
What would you like to do?
Golang: returns first n UTF-8 character at Most
func firstNUTF8AtMost(s string, n int) string {
i := 0
for j := range s {
if i >= n {
return s[:j]
}
i++
}
return s
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment