Posted to tcl by Stu at Fri Mar 28 21:04:36 GMT 2008view raw
- # StrDivideAtStr --
- #
- # Divide string into two strings at index containing
- # divider string (default #).
- # Part of string containing divider string is discarded.
- #
- # Arguments:
- # str String to divide.
- # divStr String to match for division index.
- #
- # Results:
- # Always returns a list of two strings.
- # str result
- # ----------------------------
- # "abc#def" {"abc" "def"}
- # "abc" {"abc" ""}
- # "abc#" {"abc" ""}
- # "#def" {"" "def"}
- #
- proc StrDivideAtStr {str {divStr {#}}} {
- set index [string first $divStr $str]
- if {$index == -1} {
- return [list $str ""]
- }
- set s1 [string range $str 0 [incr index -1]]
- incr index [string length $divStr]
- set s2 [string range $str [incr index] end]
- return [list $s1 $s2]
- }
- ###