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 collect information about garbage collection?
How to Remove duplicate values from Slice?
How to count number of repeating words in a given String?
Split a character string based on change of character
How to check if a string contains a numbers in Golang?
How to play and pause execution of goroutine?
Golang Slice vs Map Benchmark Testing
How to Decode or Unmarshal bi-dimensional array of integers?
How to find out element position in slice?
User Defined Function Types in Golang