Golang ProgramsGolang Programs

What is Rune? How to get ASCII value of any character in Go?

Rune literals are just an integer value. They are "mapped" to their uni-code code-point. For example the rule literal 'a' is in reality the number 97. Below is program to find the ASCII value of any character refer Wikipedia for same
package main

import "fmt"

func ASCII(r rune) rune {
    switch {
    case 97 <= r && r <= 122:
        return r - 32
    case 65 <= r && r <= 90:
        return r + 32
    default:
        return r
    }
}

func main() {
    fmt.Println(ASCII('a'))
	fmt.Println(ASCII('A'))
	fmt.Println(ASCII('@'))
	fmt.Println(ASCII('%'))
	fmt.Println(ASCII('8'))
	fmt.Println(ASCII('-'))
}
C:\golang\codes>go run example25.go
65
97
64
37
56
45

C:\golang\codes>