Skip to content

Instantly share code, notes, and snippets.

@senorprogrammer
Created December 13, 2019 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save senorprogrammer/dcb80966e2360f5393f82787c22492be to your computer and use it in GitHub Desktop.
Save senorprogrammer/dcb80966e2360f5393f82787c22492be to your computer and use it in GitHub Desktop.
Fun with emoji string lengths
package main
import (
"fmt"
"unicode/utf8"
"github.com/rivo/uniseg"
)
func main() {
fmt.Println("Hello, playground")
a := "cat"
b := "🍿☕️🍕"
fmt.Println(len(a))
fmt.Println(utf8.RuneCountInString(a))
fmt.Println(uniseg.GraphemeClusterCount(b))
fmt.Println()
fmt.Println(len(b))
fmt.Println(len([]rune(b)))
fmt.Println(utf8.RuneCountInString(b))
fmt.Println(uniseg.GraphemeClusterCount(b))
}
@senorprogrammer
Copy link
Author

Output:

Hello, playground
3
3
3

14
4
4
3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment