How to Convert Rune to Int in Golang

To convert a rune to an int, you can use the “int()” function.

Example

package main

import "fmt"

func main() {
  r := 'B'

  intValue := int(r)

  fmt.Println("Rune as int:", intValue)
}

Output

Rune as int: 66

In this code example, a rune “r” represents the Unicode code point for the letter “B”.

You can see that we used the “int(r)” function to perform the type conversion, and the result is printed to the console.

Leave a Comment