Help - Search - Members - Calendar
Full Version: How to truncate a string before a given char...
Hydrogenaudio Forums > Hosted Forums > foobar2000 > General - (fb2k)
Jose Hidalgo
Hi folks,

Let's assume we have a tag field (called %origin% here) that can have one of these two forms :
Form 1 : %origin% = "XXX"
Form 2 : %origin% = "XXX (YYY)"
XXX and YYY being substrings of unknown length, composed of several words (i.e. with spaces) but without parenthesis.

My goal is to be able to display in each case ONLY the "XXX" part of %origin%.

Here's what I've come up to :

CODE
$if($strchr(%origin%,'(')),$left(%origin%,$sub($strchr(%origin%,'('),2)),%origin%)

But it doesn't work, and besides I think it's too complicated. Could you please have a look and tell me if there's something simpler ?

Thanks in advance. smile.gif
Purple Monkey
I think that you have an extra bracket try this.
CODE
$if($strchr(%origin%,'('),$left(%origin%,$sub($strchr(%origin%,'('),2)),%origin%)

Also the method looks sound to me.
Jose Hidalgo
Thanks, it works. smile.gif I only wish it could have been shorter...

Maybe there's room for an additional titleformat function $cut2(X,Y) that would truncate string X before the first occurrence of string Y ?

Example :
X1 = "ABC DEF GH"
X2 = "ABC DEF GH (IJK LM NO)
Y = " ("
$cut2(X1,Y) = X1
$cut2(X2,Y) = X1

I'm surprised that something similar doesn't exist already... there are lots of cases where we need to truncate a string / cut it in two / etc., don't you think ?

Just my two cents...
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.