Add structs
This commit is contained in:
26
runes/runes.go
Normal file
26
runes/runes.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package runes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func Runes() {
|
||||
s := "Hello, world!"
|
||||
fmt.Printf("%s has %d runes\n", s, utf8.RuneCountInString(s))
|
||||
|
||||
s = "നമസ്കാരം"
|
||||
fmt.Printf("%s has %d runes\n", s, utf8.RuneCountInString(s))
|
||||
|
||||
fmt.Printf("Iterating through %s:\n", s)
|
||||
for i, val := range s {
|
||||
fmt.Printf("%2d = %#U\n", i, val)
|
||||
}
|
||||
|
||||
fmt.Printf("Decoding %s:\n", s)
|
||||
for i, w := 0, 0; i < len(s); i += w {
|
||||
value, width := utf8.DecodeRuneInString(s[i:])
|
||||
fmt.Printf("Decoded rune %#U of size %d\n", value, width)
|
||||
w = width
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user