How to convert string to null-terminated one?
问题 How to convert a simple string to a null-terminated one? Example: Example string: "Test message" Here are the bytes: 54 65 73 74 20 6D 65 73 73 61 67 65 I need string with bytes like follows: 54 00 65 00 73 00 74 00 20 00 6D 00 65 00 73 00 73 00 61 00 67 00 65 00 00 I could use loops, but will be too ugly code. How can I make this conversion by native methods? 回答1: It looks like you want a null-terminated Unicode string. If the string is stored in a variable str , this should work: var bytes