Skip to content

Instantly share code, notes, and snippets.

@charlie-chiu
Created May 4, 2020 08:25
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 charlie-chiu/c75d112c578d27d6c45888709b676959 to your computer and use it in GitHub Desktop.
Save charlie-chiu/c75d112c578d27d6c45888709b676959 to your computer and use it in GitHub Desktop.
for CharlieCC
func main() {
//str := "能解此愁,唯有杜康!"
//str := `"{"data":"中文"}"`
str := []byte(`"{"data":"中文"}"`)
fmt.Printf("string: %s\n", str)
//fmt.Println("String length:", len([]rune(str)))
fmt.Println("String length:", len([]byte(str)))
fmt.Println(" Bytes length:", len(str))
fmt.Println("------------------------------------")
fmt.Println("cnt index rune char bytes")
fmt.Println("------------------------------------")
cnt := 0
for index, char := range str {
cnt++
fmt.Printf("%-2d %-2d %U %2c %X\n",
cnt, index, char, char, []byte(string(char)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment