Go 程序查找字符的 ASCII 值

此 Go 程序使用 printf 语句和字符串格式来查找并返回用户给定的字符的 ASCII 值。

package main

import (
    "bufio"
    "fmt"
    "os"
)

func main() {

    reader := bufio.NewReader(os.Stdin)

    fmt.Print("Enter Any Character to find ASCII = ")
    ch, _ := reader.ReadByte()

    fmt.Printf("The ASCII value of %c = %d\n", ch, ch)
}
SureshMac:GoExamples suresh$ go run charASCII1.go
Enter Any Character to find ASCII = j
The ASCII value of j = 106
SureshMac:GoExamples suresh$ go run charASCII1.go
Enter Any Character to find ASCII = 0
The ASCII value of 0 = 48
SureshMac:GoExamples suresh$ go run charASCII1.go
Enter Any Character to find ASCII = o
The ASCII value of o = 111

此程序允许用户输入 Rune 并查找字符的 ASCII 值。

package main

import (
    "bufio"
    "fmt"
    "os"
)

func main() {

    reader := bufio.NewReader(os.Stdin)

    fmt.Print("Enter Any Character to find ASCII = ")
    ch, _, _ := reader.ReadRune()

    fmt.Printf("The ASCII value of %c = %d\n", ch, ch)
}
Golang Program to Find ASCII Value of a Character