www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - UTF8 to ANSI (1.0)

reply jicman <cabrera_ _wrc.xerox.com> writes:
Greetings!

I have done some research on the digitalmars.com for some d code showing UTF8
to ANSI stuff, and there isn't anything that I can clearly use.

Long story short, I have about 600+ files that I need to convert from UTF8 to
ANSI.  They have different languages characters.  I can do open the files with
notepad and save them as ANSI, but, I thought that I would write a quick d
program to do this.

Can anyone point me out to a site or place where I can quickly create this
small program?

thanks,

jose
Jan 30 2009
parent reply Jarrett Billingsley <jarrett.billingsley gmail.com> writes:
On Fri, Jan 30, 2009 at 5:56 PM, jicman <cabrera_ _wrc.xerox.com> wrote:
 Greetings!

 I have done some research on the digitalmars.com for some d code showing UTF8
to ANSI stuff, and there isn't anything that I can clearly use.

 Long story short, I have about 600+ files that I need to convert from UTF8 to
ANSI.  They have different languages characters.  I can do open the files with
notepad and save them as ANSI, but, I thought that I would write a quick d
program to do this.

 Can anyone point me out to a site or place where I can quickly create this
small program?
If by "ANSI" you mean the Windows-1252/Latin-1, use std.windows.charset.toMBSz. You can then use std.string.toString to get a char[]. A simple program would look something like: import std.file; import std.windows.charset; import std.string; ... foreach(file; listdir("the_dir")) write("latin_" ~ file, toString(toMBSz(cast(char[])read(file)))); and that will write out a file "latin_<filename>" for each file in the_dir.
Jan 30 2009
parent jicman <cabrera_ _wrc.xerox.com> writes:
Jarrett Billingsley Wrote:

 On Fri, Jan 30, 2009 at 5:56 PM, jicman <cabrera_ _wrc.xerox.com> wrote:
 Greetings!

 I have done some research on the digitalmars.com for some d code showing UTF8
to ANSI stuff, and there isn't anything that I can clearly use.

 Long story short, I have about 600+ files that I need to convert from UTF8 to
ANSI.  They have different languages characters.  I can do open the files with
notepad and save them as ANSI, but, I thought that I would write a quick d
program to do this.

 Can anyone point me out to a site or place where I can quickly create this
small program?
If by "ANSI" you mean the Windows-1252/Latin-1, use std.windows.charset.toMBSz.
Yes.
 You can then use std.string.toString to
 get a char[].  A simple program would look something like:
 
 import std.file;
 import std.windows.charset;
 import std.string;
 
 ...
 
 foreach(file; listdir("the_dir"))
     write("latin_" ~ file, toString(toMBSz(cast(char[])read(file))));
 
 and that will write out a file "latin_<filename>" for each file in the_dir.
Thanks, Jarrett
Jan 31 2009