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
+21.1k Golang : Clean up null characters from input data
+17.6k Convert JSON to CSV in Golang
+28.7k Golang : Detect (OS) Operating System
+8.4k Golang : Generate Datamatrix barcode
+21.7k Golang : Setting up/configure AWS credentials with official aws-sdk-go
+13.9k Golang : Get current time
+4.7k JavaScript: Add marker function on Google Map
+7.2k Golang : How to fix html/template : "somefile" is undefined error?
+17.9k Golang : Get all upper case or lower case characters from string example
+8.9k Golang : Build and compile multiple source files
+19.9k Golang : How to get time from unix nano example
+37.6k Golang : Comparing date or timestamp