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
+9k Golang : Random Rune generator
+8.6k Golang : Eroding and dilating image with OpenCV example
+17.8k Golang : Get RGBA values of each image pixel
+12.3k Golang : Get constant name from value
+6.8k Golang : Scan files for certain pattern and rename part of the files
+18.6k Golang : Set or Add HTTP Request Headers
+3.8k Linux/MacOSX : How to symlink a file?
+18.2k Golang : Measure http.Get() execution time
+33.9k Golang : Get file last modified date and time
+6.2k Golang : How to handle file size larger than available memory panic issue
+22.9k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+35.1k Golang : Convert date or time stamp from string to time.Time type