I am creating a program where I am converting bytes into a utf-16 string. However, sometimes the string will carry over because there are trailing 0's and my string will end up like: "This is my string x00\x00\x00"
. I want to trim the string when I reach the first \x00
or x00
which indicates trailing 0's. How do I do this in python?
My problem is not a duplicate of another question linked in comments because trim() doesn't fully work. If I have a string that is "This is my string x00\x00
hi there x00\x00"
I want just "This is my string" whereas trim would return "This is my string hi there"