Displaying non UTF-8 8 bit character codes with writefln()

Regan Heath regan at netmail.co.nz
Fri Oct 5 06:12:40 PDT 2007


Stewart Gordon wrote:
> "Regan Heath" <regan at netmail.co.nz> wrote in message 
> news:fe2uf5$2gsa$1 at digitalmars.com...
>> Try printf and saving the file as a UTF-8 encoded text file...
> 
> Why, exactly, are you advocating going back to the printf abomination?

Well.. there were 2 ways to solve his problem:

1. avoid the valid utf-8 cahracter check.
2. make the console display utf-8 correctly.

To achive #1 you've gotta use printf, eg.
   printf("%c\n", 230);

To achive #2 you use chcp and lucida console, eg.
   writefln("\u00B5");

or save the file as UTF-8 and use
   writefln("µ");

> <snip>
>> Using this source saved as b5.d as a UTF-8 encoded text file 
>> (IMPORTANT) I can set my command prompt font to "Lucida Console" and 
>> execute the following commands:
>>
>> E:\D\src\tmp>chcp 65001
>> Active code page: 65001
> <snip>
> 
> This misses the point slightly.  The user shouldn't have to change the 
> codepage just to get someone else's application to work properly.

Sadly, if the application is outputting UTF-8 you don't have a choice.

> What you want is my utility library:
> http://pr.stewartsplace.org.uk/d/sutil/

Cool.  You're converting UTF-8 to the console code page I assume.

Regan


More information about the Digitalmars-d-learn mailing list