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
+10.7k Golang : Display a text file line by line with line number example
+9.3k Golang : How to tokenize source code with text/scanner package?
+9.9k Golang : How to transmit update file to client by HTTP request example
+8.6k Golang : Extract or copy items from map based on value
+5.9k Golang : Reverse by word
+5.6k Golang : Break string into a slice of characters example
+9.3k Golang : Random Rune generator
+5.4k Golang : Selection sort example
+25.6k Golang : Force your program to run with root permissions
+18.3k Mac OSX : Homebrew and Golang
+11k Golang : Clean formatting/indenting or pretty print JSON result
+5.9k Golang : Humanize and Titleize functions