Help - Search - Members - Calendar
Full Version: $if(condition,then,else) and $if(condition,then) problem
Hydrogenaudio Forums > Hosted Forums > foobar2000 > Support - (fb2k)
pstrg
0.9.2

In order to detect all Artist tags in a list that contain the "-" character, let's create a column with the following function:
$if($strchr($meta(artist),-)=0,No,Yes) so that
- if the first occurrence of "-" within the artist field is 0 (there's no "-"),
- then display No
- else display Yes
However, it works contrarywise, displaying No when actually there's "-" in the string.

The same occurs with the simpler form $if($strchr($meta(artist),-)=0,No).
kockroach
Edit: I had put something down worng. So I removed it.

I think this should work for you.
CODE
$ifequal($strchr($meta(artist),-),0,No,Yes)


This should put "Yes" if the Artist has a "-" in it, if not, it will put "No".
Cosmo

$if($strchr($meta(artist),-),Yes,No)

kockroach
QUOTE(Cosmo @ Jun 24 2006, 16:50) *

$if($strchr($meta(artist),-),Yes,No)

That is what I had originally put, but wouldn't $strchr($meta(artist),-) result in a number? That's why I changed it to what I posted above.
Cosmo
I can't explain the technical details, but basically it works for the same reason that "$if($meta(artist),Yes,No)" works. If "string" returns other than a null result, then "Yes", else "No".
foosion
QUOTE(kockroach @ Jun 25 2006, 00:10) *
That is what I had originally put, but wouldn't $strchr($meta(artist),-) result in a number?
This part of titleformatting scripts is a bit tricky. Every expression has two values: a string and a boolean value. The $strchr function returns the position where it found the character as string and whether it found the character. Control structures like $if only use the boolean value of their condition. Furthermore, the strings "0", "false", and "true" don't have any special meaning.
pstrg
QUOTE(foosion @ Jun 24 2006, 21:11) *

QUOTE(kockroach @ Jun 25 2006, 00:10) *
That is what I had originally put, but wouldn't $strchr($meta(artist),-) result in a number?
This part of titleformatting scripts is a bit tricky. Every expression has two values: a string and a boolean value. The $strchr function returns the position where it found the character as string and whether it found the character. Control structures like $if only use the boolean value of their condition. Furthermore, the strings "0", "false", and "true" don't have any special meaning.

This explains why kockroach's expression works correctly and mine evaluates wrongly.
Where is that sublety (expressions having a string and a boolean value) documented?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.