Reputation: 103
In the Go language, is there any way to convert *string
to string
? (or, for that matter, any *T
to T
?)
I have looked on the internet and through some Go documentation, but I can't find it - may have missed it.
Upvotes: 9
Views: 6303
Reputation: 92966
To turn a *T
into a T
, use the *
operator:
func Dereference(strptr *string) string {
return *strptr
}
I highly suggest you to read about pointers before proceeding with the language. They are a fundamental concept without which it is impossible to use the language efficiently.
Upvotes: 9