Runes and String Encoding
What Does This Mean?
Assignment
1
Run the code as-is
package main
import (
"fmt"
"unicode/utf8"
)
func main() {
const name = "boots"
fmt.Printf("constant 'name' byte length: %d\n", len(name))
fmt.Printf("constant 'name' rune length: %d\n", utf8.RuneCountInString(name))
fmt.Println("=====================================")
fmt.Printf("Hi %s, so good to have you back in the arcanum\n", name)
}RESULTS
constant 'name' byte length: 5
constant 'name' rune length: 5
=====================================
Hi boots, so good to have you back in the arcanum2
Update the name variable to the bear emoji
π»package main
import (
"fmt"
"unicode/utf8"
)
func main() {
const name = "π»"
fmt.Printf("constant 'name' byte length: %d\n", len(name))
fmt.Printf("constant 'name' rune length: %d\n", utf8.RuneCountInString(name))
fmt.Println("=====================================")
fmt.Printf("Hi %s, so good to have you back in the arcanum\n", name)
}RESULTS:
constant 'name' byte length: 4
constant 'name' rune length: 1
=====================================
Hi π», so good to have you back in the arcanum