Request: $ltrim() and $rtrim() functions


#1

It doesn't make much sense requiring the use of regular expressions to perform such simple tasks. These functions are commonly available in most programming languages.


#2

$trim($left(x,n))

$trim($right(x,n))


#3

Wrong.


#4

What makes sense is always a point of view.

For a Mp3tag beginner the predefined converter and action dialogs are the first tools of choice.
Understanding the usage of the percentage symbol for referencing the content of a tag field (%TITLE%) respectively for defining a placeholder (%1) within a "format string" is heavy stuff enough.

The next level is understanding the Mp3tag Scripting Language and practical application of the standard functions, which are named and do work similar like the basic standard functions within other programming languages.

Using regular expressions is the third level. The Regular Expression language offers big power to handle nearly all (just all?) either simple or complicated tasks of text manipulation. But often the developing costs too much time and the expressions are hard to write and to read and to test.

Another point of view will be there on the level of the machine CPU.
How many cycles or milliseconds have the CPU to run to perform a $trim() or $ltrim() function, and in opposite how many CPU time costs the work on evaluating and performing a regular expession?

And does saving of time any matter when working with files in a file tagging process, user or batch driven from within Mp3tag?
Would a $ltrim() function save any time against a regular expression with the same functionality?
This is the question how such a trimming algorithm is implemented and will run on a specific machine CPU.

Going back to the viewpoint of a simple Mp3tag user.
A user might think:
"Hmm, I want to cut some characters at the left edge of a string, the number of characters may vary, but the characters themselves are known. The right edge of the string should never be touched. Well, there is already a clever Trim function, but it cut characters at the right edge too! Hey, I only need a LeftTrim function, where can I find it? Or can I build myself such a desired functionality out of the given tool set?"

Yes there are possibilities to reach the goal.
If someone needs a LeftTrim functionality in Mp3tag, then following workarounds can be used, demonstrated by example:

Filename before:
01 _Venus_Air_TW_2004 .mp3
Goal: Eliminate digits, underscores and spaces at the left edge of the filename.

Regular expression:
$regexp(%FILENAME%,'^[0-9 ]*',)

Standard functions:
$trim($trim(%FILENAME%$char(7),'0123456789 '),$char(7))

Filename after:
Venus_Air_TW_2004 .mp3

If someone needs a RightTrim functionality in Mp3tag, then following workarounds can be used, demonstrated by example:

Filename before:
01 _Venus_Air_TW_2004 .mp3
Goal: Eliminate digits, underscores and spaces at the right edge of the filename.

Regular expression:
$regexp(%FILENAME%,'[0-9 ]*$',)

Standard functions:
$trim($trim($char(7)%FILENAME%,'0123456789 '),$char(7))

Filename after:
01_ Venus_Air_TW.mp3

DD.20100529.1322.CEST


#5

It would save a great deal of time for anyone unfamiliar with regular expressions.

It was a simple request. IMO the function library could use some fleshing out.


#6

I'll add $TrimLeft and $TrimRight to the next release.

Kind regards
Florian