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: Remove X characters from beginning/ending of a Value or even a specific term (Read 4659 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Remove X characters from beginning/ending of a Value or even a specific term

With Foobar2000 being one of the most powerful media players out there I want to be able to do remove/trim extra characters from the left/right of a value or a specific term within a value using nothing but just the default bare-bone components that this player comes with (yes, that means I don't want to depend on other components like Masstagger).

EXAMPLE
======

In this particular example I will be demonstrating the idea of removing extra characters from the title-field.
So, with this particular release that I have; VRSYJNES - Exposure (Or lack thereof) (2016), and as you can see this release has tracknumber mixed in with title like so:



According to the image example above, the specific X-amount of characters is (3), because look at the extra characters for the 2nd-track in the image which is "2. NoSupport".

SOLUTION
=======

1. Removing X-amount of characters from Left (beginning of a field)
+ e.g. modify "01. Foo Bar" > "Foo Bar"
- none, so far.

2. Removing X-amount of characters from Right (ending of a field)
+ e.g. modify "Foo Bar 02." > "Foo Bar"
- none, so far.

3. Removing specific term(s) off a field (any matching characters / words / phrases)
+ e.g. modify "Foo 03. Huh? Bar" > "Foo Bar"
- none, so far.



# Last Updated 20160218

Re: Remove X characters from beginning/ending of a Value or even a specific term

Reply #1
This is your friend:
http://wiki.hydrogenaud.io/index.php?title=Foobar2000:Title_Formatting_Reference

Since you are most likely confused about what you usually put in the two textareas ('source' and 'pattern'), think of it like this: source is where you can manipulate the string you are working with (add things to it, replace). while 'pattern' lets you specify how you will want to chop that (presumably) long string into pieces and which parts you will want to keep.

1. Removing X-amount of characters from Left (beginning of a field)
+ e.g. modify "01. Foo Bar" > "Foo Bar"
In your example %title%, aka '01. Foo Bar' is 11 characters long. You want to cut the first part, which is 4 characters. That is however the same thing as saying 'only keep all the other characters on the right'. Namely all 11-4=7 of them. For that you can use the $right() function:
$right(%title%,[/color]7)

Obviously nobody wants to count the length of the string every time, so foobar can do it for us using the function $len():
$len(%title%)

With that we can determine the amount of characters we want to keep on the right using what we learned above, our arbitrary number 4 and the subtraction function:
$sub($len(%title%),4)

With that we can finally tell foobar how many characters we want to keep on the right from our original string %title%, with the help of the function $right():
$right(%title%,$sub($len(%title%),4))

----

With all this said in the specific case of using the Automatically Fill Values dialog (the one you are looking at) though there is a much easier way to do this. Namely you can input %title% to the 'source' textfield and %tracknumber%. %title% to 'pattern'. By this you are simply cutting your title into multiple pieces.

Inputting %tracknumber% tells foobar that the entire source string (%title% in this case) needs to be copied to %tracknumber%.

Inputting %tracknumber%. (note the period at the end) tells foobar to look for the first period in %title% and up until that point copy everything to %tracknumber%.

Inputting %tracknumber%. %title% tells foobar to look for the first period, copy everything before it into %tracknumber%, then look for the next space and copy everything after into %title%.

Inputting %tracknumber%. %title%|%artist% would tell foobar to put everything into %tracknumber% before the first period, then look for the first space, then look for the first | character and put everything inbetween those into %title%. After this put anything remaning into %artist% and so on.



2. Removing X-amount of characters from Right (ending of a field)
+ e.g. modify "Foo Bar 02." > "Foo Bar"
Same thing as above, you are just replacing every $right() with $left().


3. Removing specific term(s) off a field (any matching characters / words / phrases)
+ e.g. modify "Foo 03. Huh? Bar" > "Foo Bar"
- none, so far.
$replace(<where to look for things that need to be replaced>,<what do you want to replace>,<what do you want to put in its place>)
$replace(%title%,' Huh? ',)


Note that the orange part is missing in the second example because removing something is the same as replacing it with nothing. Also note that the green part is enclosed with ' ' which is necessary if you are going to use special characters like , ( ) [ ] in your script which have other meanings in the titleformatting syntax and would mess up the code normally.

Re: Remove X characters from beginning/ending of a Value or even a specific term

Reply #2
Ignore the leftover [/color] in my first bold example. The correct writing is: $right(%title%,7)

Re: Remove X characters from beginning/ending of a Value or even a specific term

Reply #3
[SOLVED] 20160219

By using the (3) string functions suggested by Daeron are we then able to remove characters from field-values (especially in the three different ways to remove characters from field-values).

This is your friend:
http://wiki.hydrogenaud.io/index.php?title=Foobar2000:Title_Formatting_Reference

This is where you get all the info on the syntax that Foobar2000 uses. The only problem is this reference doesn't provide examples for each function ??? (thought, i'd point that out).

Quote
In your example %title%, aka '01. Foo Bar' is 11 characters long. You want to cut the first part, which is 4 characters. That is however the same thing as saying 'only keep all the other characters on the right'. Namely all 11-4=7 of them. For that you can use the $right() function:
$right(%title%,[/color]7)

(But in most situations you'll find yourself needing an alternative method by using:)
- $len()
- $sub()
- $replace()

Luckily you went even further by explaining in the next example after this. This is because I realized that this static method doesn't work when editing multiple tracks with different value-lengths  :)  .

So my request can be done via the (3) following string functions:
1. $len(a)
2. $sub(a,b)
3. $replace(a,b,c)

A) Removing characters from the beginning of a field
+ Replace 'x' with the inter-amount e.g. '01. ' = "4" (including spaces)
- $right(%title%,$sub($len(%title%),x))
B) Removing characters from the end of a field
+ Replace 'x' with the inter-amount e.g. '002. ' = "5" (including spaces)
- $right(%title%,$sub($len(%title%),x))
C) Removing specific characters / phrases
+ Replace 'x' with the characters / phrases used e.g. 'Prod. by' = "Prod. by"
- $replace(%title%,'x',)

Re: Remove X characters from beginning/ending of a Value or even a specific term

Reply #4
Correction (Method B):

In order to remove fields from the end of a field (or the right of a field), replace the string function `$right` to `$left`

B) Removing characters from the end of a field
+ Replace 'x' with the inter-amount e.g. '002. ' = "5" (including spaces)
- $left(%title%,$sub($len(%title%),x))

Re: Remove X characters from beginning/ending of a Value or even a specific term

Reply #5
I'm trying to batch attach album covers to MP3 files. Usually the JPG files are in format %artist% - %album%, but because EAC removes certain characters in file names for example : (colon) is replaced by a space. This is what I'm trying to do:

F:\_jpg\$replace(%artist%,':',' ') - $replace(%album%, ':', ' ').jpg

...but it's not working. Can someone explain what I'm doing wrong?

Re: Remove X characters from beginning/ending of a Value or even a specific term

Reply #6
I'm trying to batch attach album covers to MP3 files. Usually the JPG files are in format %artist% - %album%, but because EAC removes certain characters in file names for example : (colon) is replaced by a space. This is what I'm trying to do:

F:\_jpg\$replace(%artist%,':',' ') - $replace(%album%, ':', ' ').jpg

...but it's not working. Can someone explain what I'm doing wrong?
Much easier to use MP3Tag for that sort of thing.
It's your privilege to disagree, but that doesn't make you right and me wrong.

Re: Remove X characters from beginning/ending of a Value or even a specific term

Reply #7
Thanks, I was actually just doing it manually with MP3Tag as we speak! Gonna have a look at that tomorrow.

Re: Remove X characters from beginning/ending of a Value or even a specific term

Reply #8
I got it to work on MP3Tag. With the exact same string I wrote above, BTW. It's a pity this doesn't work in Foobar, MP3Tag is clearly superior in this regard. Thank you so much for pointing me in that direction!

Like I wrote in another thread, adding the possibility of embedding cover art while batch converting to MP3 would make Foobar the perfect software to me. It's a pity this functionality is missing, all the more that copying images along while converting is implemented in a faulty way and thus useless.

Re: Remove X characters from beginning/ending of a Value or even a specific term

Reply #9
In a radio streaming (see photo) I have very long information in the title tag with the expression

$left(%title%,$sub($len(%title%),'115. ' = "5"))

i can delete, but, since the flow information is dynamic and changes continuously, the characters to be eliminated or added at the end change accordingly. Can this be remedied in any way?

Another question. The tilde ~ character also appears in the flow and I delete it like this:

$replace($replace(%title%,~, - ),,)

I can't write a single line that includes the two fixes of the flow.

Is it possible to do something here too?