WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: JTaylor on March 28, 2019, 11:29:19 AM

Title: StrCoalesce()
Post by: JTaylor on March 28, 2019, 11:29:19 AM
Assuming I haven't overlooked it a StrCoalesce() function would be handy.  Not sure why I hadn't thought to suggest it before but would save a lot of "IF" statements in certain situations.  Thanks.


Jim
Title: Re: StrCoalesce()
Post by: td on March 28, 2019, 01:19:53 PM
What exactly would we wish this function to do?   For example, in SQL the coalesce function usually returns the first non-null expression in a list in most implementations.
Title: Re: StrCoalesce()
Post by: JTaylor on March 28, 2019, 02:23:26 PM
Should have been a bit more specific.  Yes.  The same thing.   I process a lot of data, which you have probably figured out by now and working on something now where I have to extract a column and if it is blank then extract another for that value and so on.   Was thinking something like...

   value = StrCoalesce(ItemExtract(12,list,@TAB),ItemExtract(13,list,@TAB),ItemExtract(14,list,@TAB))

would be better than something like:

   value = ItemExtract(12,list,@TAB)
   If value == "" Then value = ItemExtract(13,list,@TAB)
   If value == "" Then value = ItemExtract(14,list,@TAB)


...and Yes, I know I could write a function to do the same.

Thanks.


Jim
Title: Re: StrCoalesce()
Post by: td on March 29, 2019, 07:31:44 AM
I guess that if I were rolling my own, I would implement a UDF with a "for" loop.  Or if speed was critical, use a UDS with "for" loop unrolling optimization if the list was typically long enough to gain from unrolling.