INTERACT FORUM
More => Old Versions => JRiver Media Center 19 for Windows => Topic started by: InflatableMouse on September 21, 2013, 01:49:11 pm
-
This isn't the first time, like here (http://yabb.jriver.com/interact/index.php?topic=82626.0;topicseen) for example. In that thread a regex solved the issue that replaces a comma with a dot.
This time its in a custom field, [Album DR]. It gives a value with 2 decimals with a comma instead of a dot. I've been trying to wrap my head around the regex and I've been reading the wiki on regex() but I can't figure it out.
Some help with this would be appreciated.
Tx!
-
If you just want to replace comma's with dots, use Replace(value, /,, .).
If there is something other than this, can you show the example values, etc.?
-
Funny, I didn't expect that to work as its an operation on a string. I guess I could have known it would work as removing the last 3 also evaluates it as an int.
Initially I made it work by removing the last 3 characters:
if(compare(RemoveRight([Album DR],3),<,7),<font color="FF0000">Album DR: [Album DR]<//font>,if(isrange(RemoveRight([Album DR],3),8-11),<font color="FFD800">Album DR: [Album DR]<//font>,if(icompare(RemoveRight([Album DR],3),>,11),<font color="4CFF00">Album DR: [Album DR]<//font>,[Album DR])))
I replaced it with
if(compare(replace([Album DR],/,,.),<,7),<font color="FF0000">Album DR: [Album DR]<//font>,if(isrange(replace([Album DR],/,,.),8-11),<font color="FFD800">Album DR: [Album DR]<//font>,if(icompare(Replace([Album DR],/,,.),>,11),<font color="4CFF00">Album DR: [Album DR]<//font>,[Album DR])))
Seems to work fine.
Makes me wonder though, does MC dynamically convert strings to integers? With the comma it was evaluated as a string, remove 3 trailing chars and it works as an integer. Replace the comma with a dot also works as an integer. Smart.
-
MC doesn't have strong typing in the expression language, which works primarily with strings of characters. When necessary, I opportunistically converts these strings into numbers, but only if the conversion works and only as much as makes sense. For example:
compare(3, >, 2) => 1
compare(3x, >, 2) => 1
compare(x3, >, 2) => 0
Here's a trick using a saved variable to avoid the repeated sub-expressions, and I've rewritten the expression to use ifelse():
save(replace([Album DR],/,,.), val)/
ifelse(
compare([val],<,7),
<font color="FF0000">Album DR: [Album DR]<//font>,
compare([val],>,11),
<font color="4CFF00">Album DR: [Album DR]<//font>,
isrange([val],8-11),
<font color="FFD800">Album DR: [Album DR]<//font>,
1,
[Album DR]
)
-
Ah very elegant. That's one I need to remember as I tend to fiddle with nested if's a lot.
Just noticed 7 to 7.99 wasn't included ;).
Tx.
-
I noticed you also has "icompare" above. Typo fixed.
-
That's funny, I hadn't noticed that because its working fine with that typo :). I would think since that eval result is false, text should be the default grey but its green.
I must be missing something... ?
-
Try these to see what's happening:
if(i0, T, F)
if(i1, T, F)
The strings "i0" and "i1" when evaluated as Boolean values always result in true.
-
Ah I see it. It's evaluating this as a string: "icompare(Replace([Album DR],/,,.),>,11)" and since there's nothing to compare with, it's true, right?
-
Ah I see it. It's evaluating this as a string: "icompare(Replace([Album DR],/,,.),>,11)" and since there's nothing to compare with, it's true, right?
The "compare" function is found and used - MC's expression parser finds the first possible longest match when looking for function names; so icompare(...) results in appending an "i" to the output of the compare() function's resultant output string.
This isn't a common scripting language syntax, as there are built-in ambiguities. Almost all scripting languages use terminators and separators to help the language parser and to avoid such ambiguities.
As far as the truth value of an arbitrary string, that's just the way its defined. If there is a value, any non-zero value, it is considered as a TRUE value in an If() statement. This isn't uncommon. In otherwords, there are only two FALSE conditions: 0 and empty. Everything else is TRUE.