Forum Discussion
Kai_Wilke
Mar 29, 2017MVP
Hi RoutingLoop,
you may try a combination of
[string last]
and [string range]
to find the position of the last occurrence and to cut the leading/trailing values.
set input "test@test@test.de"
set last_at [string last "@" $input]
set leading_part [string range $input 0 [expr { $last_at - 1 }]]
set trailing_part [string range $input [expr { $last_at + 1 }] end]
... or you could try a combination of
[split]
, [lrange]
, [lindex]
and [join]
to create and select the required [list]
entries and to format the resulting string.
set input "test@test@test.de"
set input_list [split $input "@" ]
set leading_part [join [lrange $input_list 0 end-1] "@"]
set trailing_part [lindex $input_list end]
Note: Performance wise both example are almost equal. So it will depend only on your personal preferences.
Cheers, Kai