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.2k Golang : How to add color to string?
+5.4k Javascript : How to loop over and parse JSON data?
+11.2k Google Maps URL parameters configuration
+9.5k Golang : Detect Pascal, Kebab, Screaming Snake and Camel cases
+9.8k Golang : Load ASN1 encoded DSA public key PEM file example
+6k Golang : Compound interest over time example
+9.1k Golang : Handle sub domain with Gin
+19.3k Golang : Populate dropdown with html/template example
+25.6k Golang : convert rune to integer value
+10.9k PHP : Convert(cast) bigInt to string
+10.1k Golang : Test a slice of integers for odd and even numbers
+17.5k Golang : Linked list example