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

**URL:** https://community.mp3tag.de/t/request-ltrim-and-rtrim-functions/10478
**Category:** General Discussion
**Created:** [May 27, 2010, 4:50pm UTC](https://community.mp3tag.de/t/request-ltrim-and-rtrim-functions/10478 "2010-05-27T16:50:46Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![JJ\_Johnson](https://community.mp3tag.de/user_avatar/community.mp3tag.de/jj_johnson/32/67_2.png) [@JJ\_Johnson](https://community.mp3tag.de/u/JJ_Johnson)
#### Post date: [May 27, 2010, 4:50pm UTC](https://community.mp3tag.de/t/request-ltrim-and-rtrim-functions/10478/1 "2010-05-27T16:50:46Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![sxm6qxtrg6](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/50afbb/32.png) [@sxm6qxtrg6](https://community.mp3tag.de/u/sxm6qxtrg6)
#### Post date: [May 28, 2010, 6:49pm UTC](https://community.mp3tag.de/t/request-ltrim-and-rtrim-functions/10478/2 "2010-05-28T18:49:13Z")

</div>

> [@JJ Johnson](#):
>
> It doesn't make much sense requiring the use of regular expressions to perform such simple tasks.

$trim($left(x,n))

$trim($right(x,n))

---

<div class="post-metadata">

### Author: ![JJ\_Johnson](https://community.mp3tag.de/user_avatar/community.mp3tag.de/jj_johnson/32/67_2.png) [@JJ\_Johnson](https://community.mp3tag.de/u/JJ_Johnson)
#### Post date: [May 28, 2010, 6:53pm UTC](https://community.mp3tag.de/t/request-ltrim-and-rtrim-functions/10478/3 "2010-05-28T18:53:06Z")

</div>

Wrong.

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [May 29, 2010, 5:18am UTC](https://community.mp3tag.de/t/request-ltrim-and-rtrim-functions/10478/4 "2010-05-29T05:18:40Z")

</div>

> [@JJ Johnson](#):
>
> 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.

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%,'\[1\]\*',)**

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

* * *

1. 0-9\_

---

<div class="post-metadata">

### Author: ![JJ\_Johnson](https://community.mp3tag.de/user_avatar/community.mp3tag.de/jj_johnson/32/67_2.png) [@JJ\_Johnson](https://community.mp3tag.de/u/JJ_Johnson)
#### Post date: [May 29, 2010, 5:28am UTC](https://community.mp3tag.de/t/request-ltrim-and-rtrim-functions/10478/5 "2010-05-29T05:28:13Z")

</div>

> [@DetlevD](#):
>
> Would a $ltrim() function save any time against a regular expression with the same functionality?

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.

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [November 8, 2010, 2:03pm UTC](https://community.mp3tag.de/t/request-ltrim-and-rtrim-functions/10478/6 "2010-11-08T14:03:05Z")

</div>

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

Kind regards  
Florian

---

<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: [April 5, 2022, 8:32pm UTC](https://community.mp3tag.de/t/request-ltrim-and-rtrim-functions/10478/7 "2022-04-05T20:32:33Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
