So I have a program that needs data to be converted from byte array to string.
In my usecase, the byte array is getting converted to string “value” (as seen on debug console).
How do I ignore all the \x00 values?
Thank you
So I have a program that needs data to be converted from byte array to string.
In my usecase, the byte array is getting converted to string “value” (as seen on debug console).
How do I ignore all the \x00 values?
Thank you
Please paste your code instead of using a picture. Use the icon </> above when you submit your question. Like this
byteArray := []byte{'H', 'e', 'l', 'l', 'o'}
str := string(byteArray)
fmt.Println(str)
strings.ReplaceAll(input,"\x00","")
//or
strings.Trim(intput,"\x00")
As for the difference between the two, please refer to the usage
You can combine it in different ways and operate over bytes array or string. Something like string(bytes.Trim(value, “\x00”))
or strings.Trim(string(value), “\x00”)
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.