Thread overview | |||||
---|---|---|---|---|---|
|
January 30, 2009 UTF8 to ANSI (1.0) | ||||
---|---|---|---|---|
| ||||
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 |
January 30, 2009 Re: UTF8 to ANSI (1.0) | ||||
---|---|---|---|---|
| ||||
Posted in reply to jicman | 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. |
January 31, 2009 Re: UTF8 to ANSI (1.0) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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 |
Copyright © 1999-2021 by the D Language Foundation