3 Answers
3

To remove a specific string when it is at the end, you don't use string trimright (it's second argument is really a character set and only happens to be written as a string). Instead, you should use a regsub or some code like this:

No, you can't use string trimright. As man page says, string trimright removes any trailing character belonging to the second argument. Therefore, if you do

string trimright a.a.b a.b

it starts from the end of a.a.b and removes any of a, ., or b, leaving you with the empty string.

To perform what you need, you can use a regular expression with the regsub command:

regsub {a\.b$} a.a.b ""

gives you the right string

a.

The regular expression (first argument) says: take an a character, followed by a literal . character (escaped with the back slash, because . means any character), followed by a b, at the end of the string ($).

This way you are not limited to the a and b characters, but you can also make it more general: