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
Golang String Concatenation
Example to use Weekday and YearDay function
How to check if a string contains certain characters in Golang?
Find element in a slice and move it to first position?
Get Year, Month, Day, Hour, Min and Second from a specified date
How to remove symbols from a string in Golang?
How to set, get, and list environment variables?
How to Remove duplicate values from Slice?
How to Unmarshal nested JSON structure?
How to use function from another file golang?