writefln and ASCII

Oskar Linde oskar.lindeREM at OVEgmail.com
Tue Sep 12 05:17:13 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).

0x96 is not valid ASCII. Nothing above 0x7F is valid ASCII (7-bit).

> 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...

If your raw data is Latin-1 (ISO 8859-1):

ubyte[] src;
char[] dst;
foreach(s; src)
	std.utf.encode(dst,cast(dchar)s);


/Oskar



More information about the Digitalmars-d-learn mailing list