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
+12k Golang : Get user input until a command or receive a word to stop
+6k Golang : A simple forex opportunities scanner
+22.2k Golang : Print out struct values in string format
+9.1k Golang : Read file and convert content to string
+9.6k Golang : Get UDP client IP address and differentiate clients by port number
+4.1k Golang : micron to centimeter example
+18.3k Golang : Count JSON objects and convert to slice/array
+29.7k Golang : Get local IP and MAC address
+19k Golang : Secure(TLS) connection between server and client
+20.1k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+5.5k Golang : Calculate diameter, circumference, area, sphere surface and volume
+14.2k Golang : Get current time from the Internet time server(ntp) example