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
+9.2k Facebook : Getting the friends list with PHP return JSON format
+15.7k Golang : Read large file with bufio.Scanner cause token too long error
+10.6k PHP : Convert(cast) bigInt to string
+8.1k Golang : Implementing class(object-oriented programming style)
+8k Golang : Add build version and other information in executables
+20.6k Golang : Convert PNG transparent background image to JPG or JPEG image
+12.8k Swift : Convert (cast) Int to String ?
+11.4k Get form post value in Go
+4.7k Nginx and PageSpeed build from source CentOS example
+6.1k Golang : How to search a list of records or data structures
+13.2k Facebook PHP getUser() returns 0
+12k Golang : Flush and close file created by os.Create and bufio.NewWriter example