$if doesn't recognise string as empty, and how to check if a string consists of numbers |
This is NOT a tech support forum.
Tech support questions go to foobar2000 Tech Support forum instead.
See also: Hydrogenaudio Terms of Service.
![]() ![]() |
$if doesn't recognise string as empty, and how to check if a string consists of numbers |
Jun 19 2012, 23:47
Post
#1
|
|
|
Group: Members Posts: 54 Joined: 24-March 12 Member No.: 98049 |
Strange formatting behaviour... Current track has title "01 - Party".
CODE $left(%title%,2) returns 01 (as expected). CODE $if($replace(01,01,),a,b) returns b (as expected). CODE $if($replace($left(%title%,2),01,),a,b) returns a (instead of b). Bug or my misunderstanding? -------------------- Magically yours
Raistlin |
|
|
|
Jun 20 2012, 02:36
Post
#2
|
|
![]() Group: Super Moderator Posts: 1813 Joined: 24-July 02 Member No.: 2776 |
$if does not check for a non-empty string, but for the expression's boolean value.
%title% is true if present, which remains unchanged by string manipulation functions like $left or $replace. Boolean values are most relevant for brackets (e.g., [%tracknumber%. ]), where plain text is ignored as false if no field is present. They are also the reason why functions like $and or $longer can be used with $if without returning any text. For use with brackets, it might be worth considering if $replace should return false for empty results, though. Exercise: Explain why $if($replace(01,02,),a,b) returns b. -------------------- foobar2000.audiohq.de
|
|
|
|
Jun 20 2012, 08:50
Post
#3
|
|
|
Group: Members Posts: 54 Joined: 24-March 12 Member No.: 98049 |
Thanks, I got it. This way it works:
CODE $iflonger($replace($left(%title%,2),01,),0,a,b) The main goal of mine is to check if given string consists of numbers or not. Is there a way to check this but using $replace 10 times in a row and then using $iflonger? -------------------- Magically yours
Raistlin |
|
|
|
Jun 20 2012, 09:49
Post
#4
|
|
![]() Group: FB2K Moderator (Donating) Posts: 4219 Joined: 24-February 03 Member No.: 5153 |
The following code exploits the way text is parsed as a number:
CODE $ifgreater(%title%0,%title%,a,b) If %title% contains only digits, %title%0 will represent a number that is ten times larger than the one represented by %title%. If %title% contains only zeros, this code will incorrectly return b. This can be fixed by adding a prefix to guarantee the number is not zero: CODE $ifgreater(1%title%0,1%title%,a,b) In both cases the parsing stops at the first non-digit character, i.e. "1a2" evaluates to 1 and "1a20" also evaluates to 1. Note that both code fragments return b for negative numbers and they disagree on the empty string. -------------------- http://foosion.foobar2000.org/ - my components for foobar2000
|
|
|
|
Jun 21 2012, 23:01
Post
#5
|
|
|
Group: Members Posts: 54 Joined: 24-March 12 Member No.: 98049 |
foosion
QUOTE they disagree on the empty string Empty string returns FALSE which is correct - it doesn't consist of numbers. So I don't see what to note here. Thank you very much for your explanations! -------------------- Magically yours
Raistlin |
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 19th May 2013 - 08:22 |