点击运行
package main import ( "fmt" ) func printBytes(s string) { fmt.Printf("Bytes: ") for i := 0; i < len(s); i++ { fmt.Printf("%x ", s[i]) } } func printChars(s string) { fmt.Printf("Characters: ") for i := 0; i < len(s); i++ { fmt.Printf("%c ", s[i]) } } func main() { name := "Hello World" fmt.Printf("String: %s\n", name) printChars(name) fmt.Printf("\n") printBytes(name) fmt.Printf("\n\n") name = "迹忆客" fmt.Printf("String: %s\n", name) printChars(name) fmt.Printf("\n") printBytes(name) }
运行结果 :
正在执行...