Reading ASCII file with some codes above 127 (exten ascii)

Paul phshaffer at gmail.com
Thu May 17 10:21:18 PDT 2012


On Monday, 14 May 2012 at 12:58:20 UTC, Graham Fawcett wrote:
> On Sunday, 13 May 2012 at 21:03:45 UTC, Paul wrote:
>> I am reading a file that has a few extended ASCII codes (e.g. 
>> degree symdol). Depending on how I read the file in and what I 
>> do with it the error shows up at different points.  I'm pretty 
>> sure it all boils down to the these extended ascii codes.
>>
>> Can I just tell dmd that I'm reading a Latin1 or ISO 8859-1 
>> file?
>> I've messed with the std.encoding module but really can't 
>> figure out what I need to do.
>>
>> There must be a simple solution to this.
>
> This seems to work:
>
>
> import std.stdio, std.file, std.encoding;
>
> void main()
> {
>     auto latin = cast(Latin1String) read("/tmp/hi.8859");
>     string s;
>     transcode(latin, s);
>     writeln(s);
> }
>
>
> Graham

Awesome! Thanks a million!


More information about the Digitalmars-d-learn mailing list