What is Rune? How to get ASCII value of any character in Go?
Example
package main
import "fmt"
func main() {
// Example - 1
str := "GOLANG"
runes := []rune(str)
var result []int
for i := 0; i < len(runes); i++ {
result = append(result, int(runes[i]))
}
fmt.Println(result)
// Example - 2
s := "GOLANG"
for _, r := range s {
fmt.Printf("%c - %d\n", r, r)
}
}
Output
[71 79 76 65 78 71]
G - 71
O - 79
L - 76
A - 65
N - 78
G - 71