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
Different ways to validate JSON string
Add N number of Year, Month, Day, Hour, Minute, Second, Millisecond, Microsecond and Nanosecond to current date-time
How to Convert string to float type in Go?
Sierpinski Carpet in Go Programming Language
How to check string contains uppercase lowercase character in Golang?
Get Set and Clear Session in Golang