似乎没什么好办法,string的话也得需要先转换成rune再反转再转成string
package main import (
"fmt"
) func reverseString(s string) string {
runes := []rune(s) for from, to := 0, len(runes)-1; from < to; from, to = from + 1, to - 1 {
runes[from], runes[to] = runes[to], runes[from]
} return string(runes)
} func main(){
testString := "abcdefg12345"
// testString := "" ans := reverseString(testString) fmt.Println(ans)
}
转自:http://blog.csdn.net/qq_15437667/article/details/51714765