how to convert string to rune in golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

To convert string to rune in golang, create map[rune]rune{} rune variable and assign value one by one, it will convert string into rune.

Follow the below tutorial if you are struggling with installing GO in windows.

Today, I will show you how do I convert string to rune in golang, as above mentioned I’m going to create rune variable.

Let’s start our Golang convert string to rune example

Convert whole string into rune example


package main
import "fmt"

func main() {
	var r = map[rune]rune{}
  str := "⌘こんにち aguidehubは" 
  for _, runeValue := range str {
      r[runeValue] = runeValue

In the above example, we have converted string to rune and printed in golang console. let’s check the output.


map[32:32 97:97 98:98 100:100 101:101 103:103 104:104 105:105 117:117 8984:8984 12371:12371 12385:12385 12395:12395 12399:12399 12435:12435]

Try it Yourself

I hope it helps you, All the best 👍.