Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove tailing characters

Tags:

tcl

Please tell me way to remove = and newline character \n from the end of string which is embedded between <>.

For example input string

set string "abcd  1234   abc=
"

i just want to remove = and new line from end

like image 752
user2901871 Avatar asked Jun 01 '26 07:06

user2901871


1 Answers

If you want to remove all = and newlines from the end, no matter how much there are, I suggest string trimright

set string "abcd  1234   abc=
"
string trimright $string =\n
set str2 "abc===="
string trimright $str2 =\n ; returns abc

If you know that the last 2 characters are =\n, you can also use string range

string range $string 0 end-2

For more complex solutions, regexp is appropriate.

like image 190
Johannes Kuhn Avatar answered Jun 04 '26 11:06

Johannes Kuhn