aboutsummaryrefslogtreecommitdiff
path: root/lib/strings/string.go
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2020-01-07 12:02:31 +0700
committerShulhan <m.shulhan@gmail.com>2020-01-07 12:02:31 +0700
commit84ba21902eef9620dc129a03f7ceec7d4ba0fc19 (patch)
treec107eb86851e27bc3a1b230b45e5ad625d251e08 /lib/strings/string.go
parent887038fe4b0373534256e95dd3acf240f6977cd8 (diff)
downloadpakakeh.go-84ba21902eef9620dc129a03f7ceec7d4ba0fc19.tar.xz
strings: add function to reverse a string
Diffstat (limited to 'lib/strings/string.go')
-rw-r--r--lib/strings/string.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/strings/string.go b/lib/strings/string.go
index 491edd7f..69e63893 100644
--- a/lib/strings/string.go
+++ b/lib/strings/string.go
@@ -164,6 +164,21 @@ func MergeSpaces(text string, withline bool) string {
}
//
+// Reverse the string.
+//
+func Reverse(input string) string {
+ r := []rune(input)
+ x := 0
+ y := len(r) - 1
+ for x < len(r)/2 {
+ r[x], r[y] = r[y], r[x]
+ x += 1
+ y -= 1
+ }
+ return string(r)
+}
+
+//
// Split given a text, return all words in text.
//
// A word is any sequence of character which have length equal or greater than