Reverse Strings in Go

Reverse Strings in Go

Learn How To Reverse Strings in GoLang

In this tutorial, we will learn how to reverse a string in Go.

Using a Rune

In this example, we will using a rune to reverse the string:

func ReverseString(str string) string {
	// Create a rune array from the string
	chars := []rune(str)

	// Reverse the string
	for i, j := 0, len(chars)-1; i < j; i, j = i+1, j-1 {
		chars[i], chars[j] = chars[j], chars[i]
	}
	// return the reverse string
	return string(chars)
}

Source Code

You can find the source code here: GitHub

Did you like it? Why don't you try also...

Is String a Palindrome?

Is String a Palindrome?

Learn How to Test if a String is a Palindrome in Go.

How to Convert GoLang Integer to String Conversion

How to Convert GoLang Integer to String Conversion

Learn how to convert integers to strings and how to convert strings to integers in GoLang

Using Makefiles For Go (GoLang) Development

Using Makefiles For Go (GoLang) Development

Learn how to run, build and, compile Go (GoLang) Applications for any Platform and Operating System using a Makefile