views:

279

answers:

3

Delphi 2010

When reading from file using readLn procedure, by default i get unicode string converted from code page 1251 (code page of windows).

How can i change this and read from file in other code page, in 1252 or UTF16 ?

A: 

You can use a TStreamReader - you can specify which encoding you want to read when constructing it.

For example, TStreamReader.Create(FileName, TEncoding.UTF8); will create a TStreamReader which can be used to read text from the file specified in FileName, using UTF-8 as the encoding.

Michael Madsen
-1. There are two aspects to the question that this answer doesn't address. One is that the source of the input is stdin, not a disk file. The other is that the current code uses `readln`, not a stream. (If that's because `readln` always uses the Windows code page, then that's fine, but please say so, or else it looks like you ignored details of the question.)
Rob Kennedy
+2  A: 

Don't use ReadLn/WriteLn for new code. As suggested by Michael Madsen use TStreamReader in SysUtils.

alex
A: 

See also this question.

Alexander