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.

https://aguidehub.com/blog/how-to-install-golang-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

main.go

package main
import "fmt"

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

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

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 👍.

Premium Content

You can get all the below premium content directly in your mail when you subscribe us

Books

Interview Questions

Soon You will get CSS, JavaScript, React Js, and TypeScript So Subscribe to it.

Portfolio Template

View | Get Source Code

Cheat Sheets

Cheat Sheets Books are basically Important useful notes which we use in our day-to-day life.

Related Posts