How to know whether a file's encoding is ansi or utf8?

Sam Hu via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 22 08:04:27 PDT 2014


On Tuesday, 22 July 2014 at 11:09:36 UTC, FreeSlave wrote:
> On Tuesday, 22 July 2014 at 09:50:00 UTC, Sam Hu wrote:
>> Greetings!
>>
>> As subjected,how can I know whether a file is in UTF8 encoding 
>> or ansi?
>>
>> Thanks for the help in advance.
>>
>> Regards,
>> Sam
>
> By ANSI do you mean Windows code pages? Text editors usually 
> use some heuristics (statistical analysis for example) to 
> determine encoding of file. Note that these methods are not 
> always accurate, so you need to provide ability to choose other 
> encoding for users.

Thanks.

Yes.It is Windows related again...I found that writefln() can
print ansi encoding files into console and shows its content
correctly under asia font environment,but this does not work for
files with UTF8 encoding;On the other hand,Tango 4 D2 branch can
print files with UTF8 encoding into console and shows its content
correctly under asia font environment.I tried a 'both-way' with
Tango but failed.So I just have a silly idea when I encountered a
file to be printed to the console,I choose writefln or Tango's
Stdout.formatln depending on the file encoding.


More information about the Digitalmars-d-learn mailing list