I'm trying to add a null character to a string but I cannot find the right syntax for it.
I've tried:
s += "\0"
and:
s += "\x00"
but both of these give me an error. In general, how to add a character, by character code, to a string?
I'm trying to add a null character to a string but I cannot find the right syntax for it.
I've tried:
s += "\0"
and:
s += "\x00"
but both of these give me an error. In general, how to add a character, by character code, to a string?
s += "\000"
adds the null character. Go is a pretty strict in what it allows for escapes in a string. \0 means you are starting an octal character code and go expects exactly 3 octal digits after the slash. You need three 0's for the null character. \x means you are starting a hex character code and again you need exactly two hex digits afterwards. \u or \U require exactly 4 and 8 hexadecimal digits after it. See: http://golang.org/ref/spec#Rune_literals For the full details from the spec.