How to reverse a string in Go?

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

How can we reverse a simple string in Go?

28条回答
  •  时光取名叫无心
    2020-12-04 07:38

    This works, without all the mucking about with functions:

    func Reverse(s string) (result string) {
      for _,v := range s {
        result = string(v) + result
      }
      return 
    }
    

提交回复
热议问题