Reading ASCII file with some codes above 127 (exten ascii)
    Paul 
    phshaffer at gmail.com
       
    Wed May 23 14:02:25 PDT 2012
    
    
  
>
> This works, though it's ugly:
>
>
>     foreach(line; uniS.splitLines()) {
>        transcode(line, latinS);
>        fout.writeln((cast(char[]) latinS));
>     }
>
> The Latin1String type, at the storage level, is a ubyte[]. By 
> casting to char[], you can get a similar-to-string thing that 
> writeln() can handle.
>
> Graham
Awesome!  What a lesson! Thannk you!
So if anyone is following this thread heres my code now.  This 
reads a text file(encoded in Latin1 which is basic ascii with 
extended ascii codes), allows D to work with it in unicode, and 
then spits it back out as Latin1.
I wonder about the speed between this method and Era's home-spun 
solution?
import std.stdio;
import std.string;
import std.file;
import std.encoding;
// Main function
void main(){
     auto fout = File("out.txt","w");
     auto latinS = cast(Latin1String) read("in.txt");
     string uniS;
     transcode(latinS, uniS);
     foreach(line; uniS.splitLines()){
        transcode(line, latinS);
        fout.writeln((cast(char[]) latinS));
     }
}
    
    
More information about the Digitalmars-d-learn
mailing list