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
+15.4k Golang : File path independent of Operating System
+10.8k Golang : Print UTF-8 fonts on image example
+15.9k Golang : Get future or past hours, minutes or seconds
+10.6k Golang : Convert decimal number(integer) to IPv4 address
+4.5k Javascript : Shuffle or randomize array example
+26.6k Get file path of temporary file in Go
+5.9k Golang : Pat multiplexer routing example
+5.1k PHP : How to check if an array is empty ?
+12.9k Golang : Get uploaded file name or access uploaded files
+9.2k Golang : How to get quoted string into another string?
+5.2k Golang : Experimental emojis or emoticons icons programming language
+5.3k Golang : Map within a map example