How do you check for nonempty string?

Adam D. Ruppe destructionator at gmail.com
Fri Apr 13 17:41:00 UTC 2018


On Friday, 13 April 2018 at 17:38:39 UTC, Dr.No wrote:
>>string s = null;
>>if(s !is null && s[0] == '/')
>
> is this correct?

No, that doesn't work if the string = "a"[$..$] for example

Just use

if(s.length && s[0])

instead


More information about the Digitalmars-d-learn mailing list