1

I have a file, which I open with FileStream and I modify the text. The standard encoding of this is UTF16. After this, I would like to upload the modified file somewhere, but that has to be in a Windows-1250 format.

How is it possible to convert UTF16 to Windows-1250 encoding?

Oh nooo
  • 478
  • 5
  • 19

1 Answers1

4

Use TEncoding to encode your string in a specific encoding.

var
  Ansi1250Enc: TEncoding;
....
Ansi1250Enc := TEncoding.GetEncoding(1250);

Then you can use GetBytes to encode a string as a byte array:

var
  EncodedBytes: TBytes;
  str: string;
....
str := ...; // get your text into a string variable by whatever means
EncodedBytes := Ansi1250Enc.GetBytes(str);

Or if you have the text stored in a string list you can save it like so:

Strings.SaveToFile(FileName, Ansi1250Enc);

Don't forget to destroy the Ansi1250Enc when you are done with it.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490