Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: $ifequal() and $ifgreater() doubt (Read 5220 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

$ifequal() and $ifgreater() doubt

I need to detect if an album tag contains a certain letter, say z

For a given track, by using $strchr(%album%,z) I can note that theres is a z char at position 7

However, for the same track
- if I use $ifequal(strchr(%album%,z),0,no,yes), the (wrong) result is no
- if I use $ifgreater(strchr(%album%,z),0,yes,no), the (wrong) result is no

Tracks that do not have a z evaluate (rightly) to no

What is wrong with the logic?

$ifequal() and $ifgreater() doubt

Reply #1
you forgot to put $ before strchr

the correct expression would be $ifgreater($strchr(%album%,z),0,yes,no)

$ifequal() and $ifgreater() doubt

Reply #2
you forgot to put $ before strchr

the correct expression would be $ifgreater($strchr(%album%,z),0,yes,no)


Of course!
Can't believe it myself.
Thanks.

$ifequal() and $ifgreater() doubt

Reply #3
Just to mention it, there is a $strstr alternative, so you need no numerical comparation:

$if($strstr($lower(%album%),z),yes,no)

($strstr is case sensitive, maybe you wouldn't need the $lower)

$ifequal() and $ifgreater() doubt

Reply #4
This is optimized, i think =)

$if($strchr(%album%,z),yes,no)

$ifequal() and $ifgreater() doubt

Reply #5
Squeller's and joule's answers are taking advantage of the fact that $strchr() and $strstr() have a numeric and also a logical result - right?
(Since in this case the character's position doesn't matter, by using the logical result the expression may be simpler).

A doubt:
Since a character may be regarded as a string with only one element, why $strchr()? Wouldn't $strstr() suffice?

$ifequal() and $ifgreater() doubt

Reply #6
Perhaps correct. I guess $strstr is a faster function and therefore better to use?

$ifequal() and $ifgreater() doubt

Reply #7
Squeller's and joule's answers are taking advantage of the fact that $strchr() and $strstr() have a numeric and also a logical result - right?
Correct.

Quote
Perhaps correct. I guess $strstr is a faster function and therefore better to use?

I have no odea. Do 10000 strstr's and strchr's, compare calculation times and let us know

$ifequal() and $ifgreater() doubt

Reply #8
I have no odea. Do 10000 strstr's and strchr's, compare calculation times and let us know


Compilation:
10000x $strchr: 315.5751359460 ms
10000x $strstr: 332.9715368853 ms

Execution:
10000x $strchr: 86.4468266917 ms
10000x $strstr: 86.9423837387 ms

This is just one of ten speed tests. There are no coherent results as to which function is faster.

Album: Fatboy Slim - Halfway Between The Gutter And The Stars (FLAC)
AMD Athlon 2800+, foobar2000 0.9.4

Nothing is impossible if you don't need to do it yourself.

$ifequal() and $ifgreater() doubt

Reply #9
thx

$ifequal() and $ifgreater() doubt

Reply #10
Just realized $strchr is just for one character (it only checks the first character of the 2nd argument), wheras $strstr can be used for comparing complete strings, but case sensitive.

$ifequal() and $ifgreater() doubt

Reply #11
Just realized $strchr is just for one character (it only checks the first character of the 2nd argument), wheras $strstr can be used for comparing complete strings, but case sensitive.

That's why I wondered about the reason for the existence of $strchr(), since $strstr() suffices and, as measured by Silverlight, is just as efficient.
Sure, quod abundat non nocet - just curious.