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
+17.7k Golang : When to use public and private identifier(variable) and how to make the identifier public or private?
+3.6k Linux/MacOSX : Search and delete files by extension
+7k Golang : Add build version and other information in executables
+13.2k Golang : Find network of an IP address
+4.5k Swift : Convert string array to array example
+7.4k Golang : Count leading or ending zeros(any item of interest) example
+6.5k Golang : Get YouTube playlist
+15.5k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+17.3k Golang : Get path name to current directory or folder
+5.9k Golang : constant 20013 overflows byte error message
+9.5k Golang : Create matrix with Gonum Matrix package example