Golang : convert rune to integer value
Just a short tutorial on how to convert a rune into integer. Converting rune to integer value can be useful for generating checksum to ensure that the message transmitted is not tempered with.
package main
import "fmt"
func main() {
r1 := rune('你')
i1 := int(r1)
fmt.Println(i1)
fmt.Println(string(i1))
r2 := rune('好')
i2 := int(r2)
fmt.Println(i2)
fmt.Println(string(i2))
r3 := rune('吗')
i3 := int(r3)
fmt.Println(i3)
fmt.Println(string(i3))
// or in a more efficient way
message := []rune{'你', '好', '吗'}
fmt.Println(message)
}
http://play.golang.org/p/J1WHRo4Qtk
Output :
20320
你
22909
好
21527
吗
[20320 22909 21527]
See also : Golang : convert rune to unicode hexadecimal value and back to rune character
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+6.2k Golang : Load DSA public key from file example
+8.3k Golang : Delay or limit HTTP requests example
+8.9k Golang : Removes punctuation or defined delimiter from the user's input
+20.9k Golang : Time slice or date sort and reverse sort example
+7.5k Golang : Web(Javascript) to server-side websocket example
+6.8k Golang : automatically figure out array length(size) with three dots
+7.3k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+12k Golang : Get URI segments by number and assign as variable example
+4.6k Golang : How to fix html/template : "somefile" is undefined error?
+7k Golang : Accept any number of function arguments with three dots(...)
+4.1k Swift : Get substring with rangeOfString() function example