Skip to content

Instantly share code, notes, and snippets.

@husobee
Created October 1, 2016 02:36
Show Gist options
  • Select an option

  • Save husobee/efa8fb99cd8c37b13ee40326821832af to your computer and use it in GitHub Desktop.

Select an option

Save husobee/efa8fb99cd8c37b13ee40326821832af to your computer and use it in GitHub Desktop.
reverse a string
package main
import (
"fmt"
)
func reverseStr(s string) string {
input := []byte(s)
for i := 0; i < len(input)/2; i++ {
input[i], input[(len(input)-1)-i] = input[(len(input)-1)-i], input[i]
}
return string(input)
}
func main() {
fmt.Println(reverseStr("blahes"))
}
@husobee

husobee commented Oct 1, 2016

Copy link
Copy Markdown
Author

sehalb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment