What is a 'dstring' in the D language?

I noticed this code:

dstring s;
// ...
if (s[0] == 'A') {    
    // ...}

dstring is not covered until later I believe. It appears it has something to do with Unicode?

Thank you,

Gary Chike

Hi Gary_Chike,
Yeah, “dstring” is related to Unicode. In D, all strings are Unicode strings, whereas strings in languages such as C and C++ are just arrays of bytes. The type “dstring” is “utf-32” encoded and it’s character type is “dchar”(We have discussed in the early chapters). According to the specification, it is an error to store non-Unicode data in the D string types; expect your program to fail in different ways if your string is improperly encoded.

You can find the more detail about encoding and it’s problems with solutions in the lesson(Characters: D's Unicode Problems and Support - Programming in D: The Ultimate Guide for Software Engineers)

1 Like