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
Most Helpful This Week
How to read names of all files and folders in current directory?
Copy an array by value and reference into another array
Functions mess (recursive anonymous function) in Golang
How to check lowercase characters in a string in Golang?
How to delete or remove element from a Map?
The return values of a function can be named in Golang