How do you check for nonempty string?

Dr.No jckj33 at gmail.com
Fri Apr 13 17:38:39 UTC 2018


s.length > 0 or s !is null?
used to C++/C#'s world I cautch myself doing something like this:

> if(s !is null && s.length > 0 && s[0] == '/)

then a I remembered the D's way, which length is probably a 
function not a property (in the C++/C#'s sense, which needs this 
as first parameter, hence s.length with s being null would result 
in error).

But it seems it's just enough:

>string s = null;
>if(s !is null && s[0] == '/')

is this correct?


More information about the Digitalmars-d-learn mailing list