Re: How do you check for nonempty string?

2018-04-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, April 13, 2018 17:38:39 Dr.No via Digitalmars-d-learn wrote: > 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

Re: How do you check for nonempty string?

2018-04-13 Thread user1234 via Digitalmars-d-learn
On Friday, 13 April 2018 at 17:41:00 UTC, Adam D. Ruppe wrote: 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 just `i

Re: How do you check for nonempty string?

2018-04-13 Thread Adam D. Ruppe via Digitalmars-d-learn
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

How do you check for nonempty string?

2018-04-13 Thread Dr.No via Digitalmars-d-learn
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.