package main import "fmt" func reverse(str string) string { var result []byte tmp := []byte(str) length := len(tmp) fmt.Println(length) fmt.Println(len(str)) for i := 0; i < length; i++ { result = append(result, tmp[length-i-1]) } return string(result) } func reverse1(str string) string{ var result string length := len(str) for i := 0; i < length; i++ { result = result + fmt.Sprintf("%c", str[length-i-1]) } return result } func main() { str := "hello world" //str := "你好" // 对中文不行 ret := reverse(str) fmt.Println(ret) ret = reverse1(str) fmt.Println(ret) fmt.Println(str) } 运行测试 go run main.go 11 11 dlrow olleh dlrow olleh hello world