How to Reverse a String in Golang? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Given a string and the task is to reverse the string. Here are a few examples. Approach 1: Reverse the string by swapping the letters, like first with last and second with second last and so on. Example: C // Golang program to reverse a string package main // importing fmt import "fmt" // function, which takes a string as // argument and return the reverse of string. func reverse(s string) string { rns := []rune(s) // convert to rune for i, j := 0, len(rns)-1; i < j; i, j = i+1, j-1 { // swap the letters of the string, // like first with last and so on. rns[i], rns[j] = rns[j], rns[i] } // return the reversed string. return string(rns) } func main() { // Reversing the string. str := "Geeks" // returns the reversed string. strRev := reverse(str) fmt.Println(str) fmt.Println(strRev) } Output: Geeks skeeG Approach 2: This example declares an empty string and then start appending the characters from the end, one by one. Example: C // Golang program to reverse a string package main // importing fmt import "fmt" // function, which takes a string as // argument and return the reverse of string. func reverse(str string) (result string) { for _, v := range str { result = string(v) + result } return } func main() { // Reversing the string. str := "Geeks" // returns the reversed string. strRev := reverse(str) fmt.Println(str) fmt.Println(strRev) } Output: Geeks skeeG Comment More infoAdvertise with us Next Article How to Reverse a String in Golang? P PranchalKatiyar Follow Improve Article Tags : Go Language Golang-String Golang-Program Similar Reads How to reverse a string in R Reversing a string means changing its order so that the last character becomes the first, the second last character becomes the second, and so on. A while loop is a control flow statement used in R programming to execute a block of code repeatedly as long as a specified condition is true. By using a 4 min read How to Split a String in Golang? In Go language, strings differ from other languages like Java, C++, and Python. A string in Go is a sequence of variable-width characters, with each character represented by one or more bytes using UTF-8 encoding. In Go, you can split a string into a slice using several functions provided in the str 3 min read How to reverse a String in Scala? In this article, we will learn to reverse a string in Scala. Reverse of a string means changing its order so that the last character becomes the first, the second-to-last becomes the second, and so on, effectively flipping the string's sequence of characters. Examples: Input: S = "GeeksforGeeks"Outp 3 min read How to Trim a String in Golang? In Go, strings are UTF-8 encoded sequences of variable-width characters, unlike some other languages like Java, python and C++. Go provides several functions within the strings package to trim characters from strings.In this article we will learn how to Trim a String in Golang.Examples := "@@Hello, 2 min read How to Replace Characters in Golang String? In Go language, strings are different from other languages like Java, C++, Python, etc. It is a sequence of variable-width characters where each and every character is represented by one or more bytes using UTF-8 Encoding. In Go strings, you are allowed to replace characters in the given string usin 4 min read Like