I have an AnsiString
and I need to convert it in the most efficient way to a TBytes
. How can I do that ?
Assuming you want to retain the same encoding you can do this
SetLength(bytes, Length(ansiStr));
Move(Pointer(ansiStr)^, Pointer(bytes)^, Length(ansiStr));
In reverse it goes
SetLength(ansiStr, Length(bytes));
Move(Pointer(bytes)^, Pointer(ansiStr)^, Length(bytes));