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
+11.8k Golang : Get user input until a command or receive a word to stop
+10.9k Golang : Get month name from date example
+3.8k Unix/Linux : How to pipe/save output of a command to file?
+9.4k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example
+13.5k Golang : Get HTTP protocol version example
+10.8k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard
+19.4k Golang : Create and resolve(read) symbolic links
+10.3k Golang : Byte format example
+8.6k Golang : Load ASN1 encoded DSA public key PEM file example
+5k Golang : Dealing with backquote
+9.3k Golang : Simple File Server
+6.8k Golang : Get all countries phone codes