Home > Enterprise >  Is there a way to print a string variable in its 2 words format?
Is there a way to print a string variable in its 2 words format?

Time:09-15

I understand that a string is a 2 words data structure where one word holds the address of the underlying slice of bytes and the word holds the length. Given a variable defined like this a := "a string literal", is there a way to view (or print) the content of the variable in its 2 words format?

CodePudding user response:

is there a way to view (or print) the content of the variable in its 2 words format?

No, because this is an unspecified implementation detail.

If you are okay with code that might brake: Use reflect.StringHeader. See unsafe.Pointer point (6) on how to do this.

Best not to do this. As said: this is a deliberately hidden implementation detail.

  •  Tags:  
  • go
  • Related