Created
December 13, 2019 00:17
-
-
Save senorprogrammer/dcb80966e2360f5393f82787c22492be to your computer and use it in GitHub Desktop.
Fun with emoji string lengths
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: