writefln and ASCII
Marcin Kuszczak
aarti at interia.pl
Tue Sep 12 05:26:59 PDT 2006
Serg Kovrov wrote:
> How do I writefln a string from ASCII file contained illegal UTF-8
> characters, but legal as ASCII? For example ndash symbol - ASCII 0x96).
>
> Is there a standard routine to convert such ASCII characters to UTF, or
> other way to get valid UTF string from arbitrary raw data? Filter or
> substitute bad characters, etc...
>
First - explanation:
If you have file with invalid UTF-8 characters it means that it is in
specific local encoding. It's not an ASCII file as ASCII is only for
characters code from 0..127.
Second -- how to cope with such files:
I used to convert files in local encoding using std.windows.charset. There
are two functions which will be useful:
char[] fromMBSz(char* s, int codePage = 0); // local encoding to UTF-8
char* toMBSz(char[] s, uint codePage = cast(uint)0); // UTF-8 to local
encoding
In my case encoding was 1250.
--
Regards
Marcin Kuszczak
(Aarti_pl)
More information about the Digitalmars-d-learn
mailing list