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
+7.5k Golang : File system scanning
+6.1k Golang : Use NLP to get sentences for each paragraph example
+7.8k Golang : get the current working directory of a running program
+6.3k Golang : How to write backslash in string?
+9.5k Golang : Generate random Chinese, Japanese, Korean and other runes
+18.7k Golang : Set, Get and List environment variables
+21.1k Golang : Convert PNG transparent background image to JPG or JPEG image
+13k Golang : http.Get example
+14.1k Golang : concatenate(combine) strings
+5.3k Responsive Google Adsense
+41.6k Golang : Convert string to array/slice