How to reverse a string in Go?

前端 未结 28 1931
天涯浪人
天涯浪人 2020-12-04 06:45

How can we reverse a simple string in Go?

28条回答
  •  萌比男神i
    2020-12-04 07:32

    For simple strings it possible to use such construction:

    func Reverse(str string) string {
        if str != "" {
            return Reverse(str[1:]) + str[:1]
        }
        return ""   
    }
    

提交回复
热议问题