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
+7.3k Golang : Rename part of filename
+22.6k Golang : simulate tail -f or read last line from log file example
+33.7k Golang : Call a function after some delay(time.Sleep and Tick)
+11.8k Golang : Sort and reverse sort a slice of runes
+12.1k Golang : Encrypt and decrypt data with x509 crypto
+16.8k Golang : How to save log messages to file?
+47.7k Golang : How to convert JSON string to map and slice
+8.6k Golang : Gaussian blur on image and camera video feed examples
+9.7k Golang : Check if user agent is a robot or crawler example
+9.2k Golang : Convert(cast) string to int64
+12k Golang : Simple client-server HMAC authentication without SSL example
+9.2k Facebook : Getting the friends list with PHP return JSON format