12.5.37    split

Description:   Split a string into a proper Tcl list

Syntax:         split string ?splitChars?

         

Argument:     string, characters

Returns:         list

See Also:       lappend,  list, length, append, lsearch, lindex, string

 

Examples:     

split "Hello world" {}

returns "H e l l o { } w o r l d".

 

#example2

# split value into lines, trimming leading and trailing

# space.

    set value2 {}

    foreach ln [split $value \n] {

        set ln [string trim $ln]

        if {[string length $ln] > 65} {

        SETVAL "text50=line longer than 65 chars"

        }

        lappend value2 $ln

    }

 

Split returns a list created by splitting string at each character that is in the splitChars argument. Each element of the result list will consist of the characters from string that lie between instances of the characters in splitChars. Empty list elements will be generated if string contains adjacent characters in splitChars, or if the first or last character of string is in splitChars. If splitChars is an empty string then each character of string becomes a separate element of the result list. SplitChars defaults to the standard blank characters.

.