GO 反转字符串

GO 反转字符串


package main

import "fmt"

func main() {
	str := "hello,world"

	bytes := []byte(str)
	lenBytes := len(bytes)
	forLen := lenBytes / 2

	for i := 0; i < forLen; i++ {
		bytes[i], bytes[lenBytes-i-1] = bytes[lenBytes-i-1], bytes[i]
	}

	fmt.Println(string(bytes))
}

posted @ 2024-03-19 18:12  等你下课啊  阅读(27)  评论(0)    收藏  举报