Welcome To Golang By Example

Print the next or previous character given a char in Go (Golang)

Table of Contents

Overview

Simply by doing plus 1 and minus 1 we can get the next and previous character given a current char.

Program

Here is the program for the same

package main

import "fmt"

func main() {
	var curr byte
	curr = 'b'

	fmt.Println(string(curr + 1))
	fmt.Println(string(curr - 1))
}

Output:

c
a

Note: Check out our Golang Advanced Tutorial. The tutorials in this series are elaborative and we have tried to cover all concepts with examples. This tutorial is for those who are looking to gain expertise and a solid understanding of golang – Golang Advance Tutorial

Also if you are interested in understanding how all design patterns can be implemented in Golang. If yes, then this post is for you – All Design Patterns Golang