I have a MemoryStream with a portion of a UCS2 File (I've extracted one line from a FileStream to the MemoryStream). I am using the funtion UTF16ToUTF8 contained in LazUTF8.pas to convert the string to UTF8 with the following code
var
Line: String;
FS: TFileStream;
PosOfSeparator: Int64;
begin
...
MS := TMemoryStream.Create;
try
MS.CopyFrom(FS {created earlier}, PosOfSeparator {# bytes to read - initialized earlier});
Line := UTF16ToUTF8(PWideChar(MS.Memory), MS.Size dive SizeOf(WideChar));
finally
MS.Free;
end;
..
end;
This works reasonably well until I have characters that are meant to be read from RIGHT TO LEFT, e.g. arabic. When I encounter arabic characters, I correctly get the arabic characters, but all the non-arabic characters that are AFTER the arabic characters, appear BEFORE the arabic characters in my LINE variable above.
Is there another method I can convert the UCS2 String to UTF8?