How to Convert Rune to String in Golang

To convert a rune to a string, you can use the “string()” function. In Go, a rune is an alias for the int32 type, representing a Unicode code point.

Example

package main

import "fmt"

func main() {
  r := rune('K')
  fmt.Println(r)

  // Convert rune to string
  s := string(r)
  fmt.Println("Rune as string:", s)
}

Output

75
Rune as string: K

This code snippet demonstrates converting a rune (in this case, the letter ‘K’) to a string.

The string() function makes the conversion, and the result is printed to the console.

Leave a Comment