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.5k Swift : Convert (cast) String to Double
+27.9k Golang : Change a file last modified date and time
+13.2k Golang : Set image canvas or background to transparent
+23.3k Golang : Fix type interface{} has no field or no methods and type assertions example
+7k Golang : alternative to os.Exit() function
+11.2k Golang : Change date format to yyyy-mm-dd
+10.5k Golang : Replace a parameter's value inside a configuration file example
+16.1k Golang : Send email and SMTP configuration example
+7.2k Golang : Get YouTube playlist
+8.9k Golang : Generate Codabar
+11.5k Golang : Convert(cast) bigint to string
+14.2k Golang : Execute function at intervals or after some delay