Search code examples
delphiunicodeutf-16

What is the most efficient way to get the UTF-16LE bytes for a Delphi UnicodeString?


As Delphi uses UTF-16 for its internal representation, is it correct to simply copy all bytes of a UnicodeString over to a byte array?

Is this platform-independent?


Solution

  • If you want to play the safe card: TEncoding.Unicode.GetBytes('Hello World'). The current implementation looks quite efficient and you don't have to worry about future platforms.