Back to Basics: Reversing a string in Golang

aString = ""A string to reverse with python"
aString = aString[::-1]
import "fmt"func reverse(r []rune) string {
for i, j := 0, len(r)-1; i < j; i, j = i+1, j-1 {
r[i], r[j] = r[j], r[i]
}
result := string(r)
return result
}
func main() { //string to reverse
s := "A string to reverse with golang."
r := []rune(s) fmt.Printf("text reversed %s\n", reverse(r))
}
$ go run main.go
text reversed .gnalog htiw esrever ot gnirts A

--

--

--

Writing to soothe the soul, programming to achieve flow

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Best Way To Download Torrent With Idm

Set up a Kafka cluster with Raspberry Pi

IS AGILE FIT FOR PURPOSE FOR SERVICE DESIGN PROJECTS?

Learning Java

How to hire and build a software development team!

Collecting logs in Azure Databricks

Creating Virtual Environment for Python — Without disturbing Conda Configuration

Guidance to setup ec2 instance to host production web service by apache + laravel

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mipsmonsta

Mipsmonsta

Writing to soothe the soul, programming to achieve flow

More from Medium

Interfaces Example in Go

Sorting Algorithms: Insertion Sort in Golang

Delve With VSCode To Debug Go App

Installing & Verifying GO in VS at MAC