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
+5.6k Golang : List all packages and search for certain package
+29.5k Golang : How to declare kilobyte, megabyte, gigabyte, terabyte and so on?
+28.4k Golang : Detect (OS) Operating System
+17.3k Golang : Parse date string and convert to dd-mm-yyyy format
+11k Use systeminfo to find out installed Windows Hotfix(s) or updates
+6.6k Golang : Decode XML data from RSS feed
+3.9k Javascript : Empty an array example
+16.8k Golang : How to save log messages to file?
+6k Javascript : Generate random key with specific length
+20.9k Golang : Convert(cast) string to rune and back to string example
+20k nginx: [emerg] unknown directive "passenger_enabled"
+7.3k Golang : Dealing with struct's private part