How to Create Null-Terminated Strings in Go
In Go, a null-terminated string is terminated by a byte with the value 0, known as the null character. Creating such a string requires escaping the null character in a way that is recognized by the compiler.
One way is to use three octal digits, each representing a byte value in base 8:
s := "golang<pre class="brush:php;toolbar:false">s := "golang\x00"
Another option is to use two hexadecimal digits, each representing a byte value in base 16:
s := "golang\u0000"
Finally, you can use a unicode sequence, with four hexadecimal digits representing a Unicode code point:
s := "golang0" fmt.Println([]byte(s)) // Prints: [103 111 108 97 110 103 0]
Example:
The above is the detailed content of How Do I Create Null-Terminated Strings in Go?. For more information, please follow other related articles on the PHP Chinese website!