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

The shopping aggregator problem.

Fun commands in Linux

10 Things to Know About Python Regex as An Advanced User

LeetCode — Find Peak Element

BlueHost VS GoDaddy

Airflow authentication with RBAC and Keycloak

How we built and voice-enabled an inventory management app with Alan AI

Create a Natural Language Question Answering system with IBM Watson

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

Functions in GO

Golang in sixty seconds — converting to JSON

Photo of JSON business card, showing logo and text “JSON Data Interchange Format”

Mocking HTTP Call in Golang a Better Way

Photo by @jim_reardan on Unsplash

Let’s GO! Part 1: A Word or Two About GO