# Weird behavior found with $if() and $strstr()

**URL:** <https://community.mp3tag.de/t/weird-behavior-found-with-if-and-strstr/48269>\
**Category:** Support\
**Created:** [March 24, 2020, 4:38pm UTC](https://community.mp3tag.de/t/weird-behavior-found-with-if-and-strstr/48269 "2020-03-24T16:38:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![CodeYan](https://community.mp3tag.de/user_avatar/community.mp3tag.de/codeyan/32/7411_2.png) [@CodeYan](https://community.mp3tag.de/u/CodeYan)\
**Post date:** [March 24, 2020, 4:38pm UTC](https://community.mp3tag.de/t/weird-behavior-found-with-if-and-strstr/48269/1 "2020-03-24T16:38:19Z")

</div>

I am creating an action group for formatting my tags and has just started playing with script functions.  
(Using Action "Format Value", with Field TITLE just to see the output first.

My filename:  
M1 - Something

Format string:

> $if(0,yes,no)

Output:

> no

I did this just to check if the if function accepts integer. (Edit: It doesn't. Even the value 1 will output 'no'.) Now to search for a string in the filename.

Format string:

> $strstr(%\_filename%,A)

Output:

> 0

Search for string worked. Now, to nest them.

Format string:

> $if($strstr(%\_filename%,A),yes,no)

Output:

> yes

Now, that's weird. It should have just substituted the value of 0, but to the if function, it appears as true?

I thought that the $strstr() might be outputting a char instead an integer (if that distinction was ever in the code, I'm not sure). But I thought to try to compare the returned value if it is greater than 0.

Workaround:

> $if($grtr($strstr(%\_filename%,A),0),yes,no)

Output:

> no

Also tried replacing the 'A' with an 'M', the output was yes, implying that the workaround succeeded.

Since it worked with the $grtr() function, shouldn't it work with the $if() function as well? I feel like this is unintentional. Fixing the $if() to work with $strstr() will surely help a lot in reducing the confusion and the script volume.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [March 24, 2020, 4:51pm UTC](https://community.mp3tag.de/t/weird-behavior-found-with-if-and-strstr/48269/2 "2020-03-24T16:51:52Z")

</div>

If you use the $if() function, it is expected that the first parameter also return a boolean data type.  
The example

> [@CodeYan](#):
>
> $if(0,yes,no)

only appears to be the correct outcome as the 0 is sometimes also taken as boolean value.  
Yet, you will also get the "not true" result, even if you enter other values like e.g. "1" or "-1".  
the $strstr() function returns a numeric value - which has to be compared to something when used in a boolean function.  
So you would have to use $if() with one or more of the other boolean functions as referenced in the help:

> **[Scripting Functions – Mp3tag Documentation](https://docs.mp3tag.de/scripting/#boolean-functions)**
>
> Documentation on Mp3tag's scripting functions. Mp3tag is the universal Tag Editor.

So I would say: everything is fine.

---

<div class="post-metadata">

**Author:** ![CodeYan](https://community.mp3tag.de/user_avatar/community.mp3tag.de/codeyan/32/7411_2.png) [@CodeYan](https://community.mp3tag.de/u/CodeYan)\
**Post date:** [March 24, 2020, 5:05pm UTC](https://community.mp3tag.de/t/weird-behavior-found-with-if-and-strstr/48269/3 "2020-03-24T17:05:13Z")

</div>

Is it not possible to accept integer values as booleans (i.e. implicitly converting them to booleans)? I believe it would be useful to make it a feature. Or is it something that everyone has already thought of?

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [March 24, 2020, 5:08pm UTC](https://community.mp3tag.de/t/weird-behavior-found-with-if-and-strstr/48269/4 "2020-03-24T17:08:16Z")

</div>

You already have shortcut functions like $ifgreater(), $iflonger() etc. These convert numeric results into boolean.

---

<div class="post-metadata">

**Author:** ![CodeYan](https://community.mp3tag.de/user_avatar/community.mp3tag.de/codeyan/32/7411_2.png) [@CodeYan](https://community.mp3tag.de/u/CodeYan)\
**Post date:** [March 24, 2020, 5:10pm UTC](https://community.mp3tag.de/t/weird-behavior-found-with-if-and-strstr/48269/5 "2020-03-24T17:10:59Z")

</div>

I see. Thanks for the swift responses.  
I have also confirmed that even the value 1 is not accepted by the if function as true. Updated the post.

Applying the $ifgreater() as @ohrenkino suggested:

> $ifgreater($strstr(%\_filename%,A),0,yes,no)

Huge thanks!

---

<div class="post-metadata">

**Author:** ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)\
**Post date:** [February 9, 2026, 12:28pm UTC](https://community.mp3tag.de/t/weird-behavior-found-with-if-and-strstr/48269/6 "2026-02-09T12:28:29Z")

</div>


