10 examples of 'golang reverse string' in Go

Every line of 'golang reverse string' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
79func reverse(s []int) []int {
80 for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
81 fmt.Println("value of i: ", i)
82 fmt.Println("value of j: ", j)
83
84 s[i], s[j] = s[j], s[i]
85 }
86 return s
87}
200func Reverse(str string) string {
201 runes := []rune(str)
202 for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
203 runes[i], runes[j] = runes[j], runes[i]
204 }
205 return string(runes)
206}
24func reverse(in string) string {
25 out := ""
26 for x := len(in) - 1; x >= 0; x-- {
27 out += in[x : x+1]
28 }
29 return out
30}
173func reverse(s string) string {
174 chars := []rune(s)
175 for i, j := 0, len(chars)-1; i < j; i, j = i+1, j-1 {
176 chars[i], chars[j] = chars[j], chars[i]
177 }
178 return string(chars)
179}
192func reverse(s string) string {
193 chars := []rune(s)
194 for i := 0; i < len(chars)/2; i++ {
195 j := len(chars) - 1 - i
196 chars[i], chars[j] = chars[j], chars[i]
197 }
198 return string(chars)
199}
316func Reverse(s string) string {
317 runes := []rune(s)
318 for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
319 runes[i], runes[j] = runes[j], runes[i]
320 }
321 return string(runes)
322}
47func reverse(t *Node) {
48 if t == nil {
49 fmt.Println("-> Empty list!")
50 return
51 }
52
53 temp := t
54 for t != nil {
55 temp = t
56 t = t.Next
57 }
58
59 for temp.Previous != nil {
60 fmt.Printf("%d -> ", temp.Value)
61 temp = temp.Previous
62 }
63 fmt.Printf("%d -> ", temp.Value)
64 fmt.Println()
65}
8func Reverse(str string) string {
9 r := []rune(str)
10 var ns strings.Builder
11
12 for idx := range r {
13 ns.WriteRune(r[len(r) - idx - 1])
14 }
15
16 return ns.String()
17}
60func reverse(s []string) []string {
61 for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
62 s[i], s[j] = s[j], s[i]
63 }
64 return s
65}
564func reverse(s []*types.Package) []*types.Package {
565 for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
566 s[i], s[j] = s[j], s[i]
567 }
568 return s
569}

Related snippets