Created
May 4, 2020 08:25
-
-
Save weinung-chiu/c75d112c578d27d6c45888709b676959 to your computer and use it in GitHub Desktop.
for CharlieCC
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
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