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
+10.3k Golang : Get login name from environment and prompt for password
+8.7k Golang : Convert(cast) []byte to io.Reader type
+46.7k Golang : Encode image to base64 example
+22.4k Golang : Match strings by wildcard patterns with filepath.Match() function
+6.1k Linux/MacOSX : Search for files by filename and extension with find command
+7.2k Golang : Get Alexa ranking data example
+17.2k Golang : Covert map/slice/array to JSON or XML format
+14.3k Golang : Check if a file exist or not
+12.5k Golang : Print UTF-8 fonts on image example
+13k Golang : Convert int(year) to time.Time type
+7.3k Golang : Gorrila mux.Vars() function example
+38.4k Golang : Read a text file and replace certain words