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.6k Golang : Pass database connection to function called from another package and HTTP Handler
+22.8k Golang : Find biggest/largest number in array
+9.4k Golang : Flip coin example
+9.9k Golang : Intercept and process UNIX signals example
+5.5k Golang : Combine slices of complex numbers and operation example
+16.3k Google Chrome : Your connection to website is encrypted with obsolete cryptography
+28.6k Golang : How to get HTTP request header information?
+14.9k Golang : Find out mime type from bytes in buffer
+26.4k Golang : Move file to another directory
+8.1k Golang : Play .WAV file from command line
+9.3k JavaScript/JQuery : Detect or intercept enter key pressed example
+12.5k Golang : unknown escape sequence error