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
+20.7k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+4.8k List of Golang XML tutorials
+4.9k Unix/Linux : How to test user agents blocked successfully ?
+8k Golang : What is the default port number for connecting to MySQL/MariaDB database ?
+18.2k Golang : How to run your code only once with sync.Once object
+10.5k SSL : The certificate is not trusted because no issuer chain was provided
+10.9k Golang : Print UTF-8 fonts on image example
+9.8k Golang : Simple image viewer with Go-GTK
+8.8k Golang : Sort and reverse sort a slice of integers
+10.8k Golang : Perform sanity checks on filename example
+17.5k Unmarshal/Load CSV record into struct in Go
+5.5k WARNING: UNPROTECTED PRIVATE KEY FILE! error message