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
+12.7k Golang : Remove or trim extra comma from CSV
+23.2k Golang : Randomly pick an item from a slice/array example
+12.2k Golang : md5 hash of a string
+6.2k Golang : Scan forex opportunities by Bollinger bands
+9.3k Golang : Generate Codabar
+19.7k Golang : Close channel after ticker stopped example
+8.3k Prevent Write failed: Broken pipe problem during ssh session with screen command
+25.3k Golang : Storing cookies in http.CookieJar example
+8.3k Golang : Metaprogramming example of wrapping a function
+12.4k Golang : Get remaining text such as id or filename after last segment in URL path
+16.5k Golang : Test floating point numbers not-a-number and infinite example
+9.5k Golang : Create unique title slugs example