A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Reverse String in Go page! Here, you'll find the source code for this program as well as a description of how the program works.
package main
import "fmt"
import "os"
//Function to reverse a string
func reverse_string(str string) string {
chars := []rune(str)
for i, j := 0, len(chars)-1; i < j; i, j = i+1, j-1 {
chars[i], chars[j] = chars[j], chars[i]
}
return string(chars)
}
func main() {
// Check the command line args length
var argslen = len(os.Args)
// If the length is 2, one command line arg exist
if argslen == 2 {
input := os.Args[1]
fmt.Printf("%v\n", reverse_string(input))
}
}
Reverse String in Go was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.