Reputation: 25
Input string : 4567-ABC
I want to remove everything before "-
" in the string so that Output will be ABC.
Output: ABC
Upvotes: 1
Views: 943
Reputation: 247210
string last
is useful here:
set string 4567-ABC
set idx [string last "-" $string]
set wanted [string range $string $idx+1 end]
Or without the intermediate variable
set wanted [string range $string [string last "-" $string]+1 end]
That even works if the original string does not contain any hyphens.
Upvotes: 1
Reputation: 1873
If you want to avoid regular expressions:
set string 4567-ABC
set output [lindex [split $string "-"] 1]
The split
command takes a string and split characters as the arguments and returns a list.
Upvotes: 1