[Logo] Jaikoz and SongKong Forums
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Ifnotempty Function Improvment  XML
Forum Index -> SongKong Questions
Author Message
chillware

Pro

Joined: 17/11/2010 13:13:39
Messages: 99
Offline

hello,

I was wondering if you can help me to write a better 'ifnotempty' function..

Currently ifnotempty outputs the specified mask and then a separator. I'd like help in writing it so it instead of a separator it outputs a string including the mask and also an else.

For example I would write something like, ifnotempty(year, ' [' + year + ']', '')

So it works kind of like an if, then, else. If NotEmpty year, then do this, else do this.

Can you help me create a ifnotempty2 that would help me to accomplish this? Thank you!!
paultaylor

Pro
[Avatar]

Joined: 21/08/2006 09:21:27
Messages: 7206
Offline

What about this
Code:
  function ifnotemptyelse(value1,value2,sep){
      return value1.length > 0 ? value2 :value2.length > 0 ? sep:'' ;
  }


use like this

Code:
 ifnotemptyelse(album,'['+album+']','')

thanks Paul (Administrator)
chillware

Pro

Joined: 17/11/2010 13:13:39
Messages: 99
Offline

Excellent, thank you!!
 
Forum Index -> SongKong Questions
Go to:   
Powered by JForum 2.1.6 © JForum Team