Rune count in a string

Report a typo

Do you know that you can store emojis in string variables?

var moai string = "🗿"

Now that you know, suppose you have a Go program that takes as input a string with one or more emojis.

Your task is to use the utf8.RuneCountInString() function to count and then print how many runes characters are in the emoji string variable.

Sample Input 1:

🗿

Sample Output 1:

1

Sample Input 2:

👨🏻‍👩🏻‍👧🏻‍👦🏻

Sample Output 2:

11

Sample Input 3:

🥅⚽🏃

Sample Output 3:

3
Write a program in Go
package main

import (
"fmt"
"unicode/utf8"
)

func main() {
var emoji string
fmt.Scanln(&emoji)

// Call the `utf8.RuneCountInString()` function below to count
// how many runes are in the `emoji` string variable:
runeCount := ?

fmt.Println(runeCount) // DO NOT delete this line; it prints the `emoji` rune count
}
___

Create a free account to access the full topic