Is there is efficient way to convert a fixed byte slice to a string without adding null characters to the string?
The traditional way to convert a string from a byte slice is the following:
out := string(b[STRIDX:STRIDX+STRLEN])
While this returns a string, the length is always equal to the byte slice length. So while the string looks normal on a Print
statement it is still referencing potentiality null values.This has some very odd effects if you append characters to this string.
Right now i scan the byte slice for nulls to limit the byte slice i feed to string
. Not very pretty or efficient.