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
+16.8k Golang : Generate QR codes for Google Authenticator App and fix "Cannot interpret QR code" error
+12.1k Golang : Setup API server or gateway with Caddy and http.ListenAndServe() function example
+6.7k Golang : How to determine if request or crawl is from Google robots
+10.3k Golang : How to get quoted string into another string?
+17.9k Golang : Iterate linked list example
+13.8k Golang : Qt progress dialog example
+41.4k Golang : How to count duplicate items in slice/array?
+6.6k Golang : Calculate diameter, circumference, area, sphere surface and volume
+3.7k Java : Get FX sentiment from website example
+16k Golang : Update database with GORM example
+8.4k Useful methods to access blocked websites
+5.9k Golang : Find change in a combination of coins example