Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get last occured string

Status
Not open for further replies.

snowingnow

Programmer
Jun 1, 2006
32
CA
That says, we have "A^cur~B1^pre~B2^pre~C^lat"
since "B1^pre~B2^pre" of pre componet could repeat more than two time, i only need to get the last one for pre component
than the result come as ""A^cur~B2^pre~C^lat", how can i do that, thanks
 
It's not clear to me what you're asking. You have an input string, A, and you want to delete all but one (consecutive?) instance of a substring, B, from that string?

_________________
Bob Rashkin
 
Yes, sorry for the confusion, i want to keep only the last one of substring B
 
Let's say the bigger string is string_a. Further, let the repeating substring, that you only want one of, is string_b. Now, assuming that the only occurrence of string_b is the consecutive recurrence somewhere in string_a but not multiple non-recurring instances:
Code:
set i1 [string first $string_b $string_a]
set i2 [string last $string_b $string_a]
incr i2 -1
set string_a [string replace $string_a $i1 $i2]

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top