Welcome To Golang By Example

Menu
  • Home
  • Blog
Menu

Swap two strings in Golang

Posted on March 16, 2023March 16, 2023 by admin

GO provides a very neat way of swapping of two strings. See below program

package main
import "fmt"
func main() {
a := "123"
b := "xyz"
fmt.Printf("Before a:%s b:%s\n", a, b)
a, b = b, a
fmt.Printf("After a:%s b:%s\n", a, b)
}

Output:

Before a:123 b:xyz
After a:xyz b:123

Popular Articles

Golang Comprehensive Tutorial Series

All Design Patterns in Go (Golang)

Slice in golang

Variables in Go (Golang) – Complete Guide

OOP: Inheritance in GOLANG complete guide

Using Context Package in GO (Golang) – Complete Guide

All data types in Golang with examples

Understanding time and date in Go (Golang) – Complete Guide

©2023 Welcome To Golang By Example | Design: Web XP