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
+37.3k Upload multiple files with Go
+33.7k Golang : convert(cast) bytes to string
+38.9k Golang : How to iterate over a []string(array)
+29.3k Golang : Record voice(audio) from microphone to .WAV file
+6.4k Golang : Totalize or add-up an array or slice example
+8k Golang : How To Use Panic and Recover
+11.4k Golang : Handle API query by curl with Gorilla Queries example
+16k Golang : How to check if input from os.Args is integer?
+14.1k Golang : Convert IP version 6 address to integer or decimal number
+35.1k Golang : Strip slashes from string example
+21.4k Golang : GORM create record or insert new record into database example