Skip to content

Instantly share code, notes, and snippets.

@hogedigo
Created December 20, 2014 04:50
Show Gist options
  • Save hogedigo/100a1e978f887eff6ceb to your computer and use it in GitHub Desktop.
Save hogedigo/100a1e978f887eff6ceb to your computer and use it in GitHub Desktop.
マルチバイトを考慮したreverse
package tool
import (
"bytes"
)
func Reverse(s string) string {
runes := make([]rune, 0, 10)
for _, r := range s {
runes = append(runes, r)
}
var buf bytes.Buffer
for i := len(runes) - 1; i >= 0; i-- {
if _, err := buf.WriteRune(runes[i]); err != nil {
return "error"
}
}
return buf.String()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment