String Type Usage. String vs DString vs WString

SimonN eiderdaus at gmail.com
Mon Jan 15 06:18:27 UTC 2018


On Monday, 15 January 2018 at 02:05:32 UTC, Chris P wrote:
> Is usage of one type over the others encouraged?

I would use string (UTF-8) throughout the program, but there 
seems to be no style guideline for this. Keep in mind two gotchas:

D's foreach and D's ranges will autodecode and silently iterate 
over dchar, not char, even when the input is string, not dstring. 
(It's also possible to explicitly decode strings, see std.utf and 
std.uni.)

If you call into the Windows API, some functions require extra 
care if everything in your program is UTF-8. But I still agree 
with the approach to keep everything as string in your program, 
and then wrap the Windows API calls, as the UTF-8 Everywhere 
manifesto suggests:
http://utf8everywhere.org/

-- Simon


More information about the Digitalmars-d-learn mailing list