Version 2 of String Difference

Updated 2011-12-13 13:02:17 by dkf

WJG (12/12/11) This simple proc arose out of the need to create text line references such as T08n0224_p0425a18(02)-T08n0224_p0425a19(00) in a more compact form, i.e T08n0224_p0425a18(02)-9(00).

#---------------
# Compare str2 to str1 until a mismatch is found. At that point return remainder of str2.
#---------------
# Arguments
#   str1   base string
#   str2   string to be compared
# Returns
#   The difference in string endings.
proc string_diff {str1 str2} {
    for {set i 0} {$i < [string length $str1]} {incr i} {
        if {[string index $str2 $i] ne [string index $str1 $i]} {
            return [string range $str2 $i end]
        }
    }
    return [string range $str2 $i end]
}