Golang : Convert(cast) uintptr to string example
Problem:
You need a fast way to convert a variable of type uintptr
to type string
without using unsafe
package. Such as storing a process ID (pid) into a plain text file.
Solution:
Use fmt.Sprint()
function to convert the uintptr
value to type string. For example:
package main
import (
"fmt"
)
var ret uintptr = 123
func main() {
fmt.Println(ret)
// if you need to store the value
// into a string variable
str := fmt.Sprint(ret)
fmt.Println(str)
}
output:
123
123
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
+5.4k PHP : See installed compiled-in-modules
+13.8k Android Studio : Password input and reveal password example
+6.3k Golang & Javascript : How to save cropped image to file on server
+7.8k Golang : Command line ticker to show work in progress
+22.9k Golang : Round float to precision example
+8.4k Golang : Auto-generate reply email with text/template package
+9.5k Golang : Find the length of big.Int variable example
+13.8k Golang : Tutorial on loading GOB and PEM files
+14.6k Golang : How to determine if user agent is a mobile device example
+25.5k Golang : Convert long hexadecimal with strconv.ParseUint example
+13.8k Golang : Set image canvas or background to transparent