![]() |
![]()
| ![]() |
![]()
NAMEsplit - Split a string into a proper Tcl list SYNOPSISsplit string ?splitChars? DESCRIPTIONReturns 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 white-space characters. EXAMPLESDivide up a USENET group name into its hierarchical components: split "comp.lang.tcl.announce" . See how the split command splits on every character in splitChars, which can result in information loss if you are not careful: split "alpha beta gamma" "temp" Extract the list words from a string that is not a well-formed list: split "Example with {unbalanced brace character" Split a string into its constituent characters split "Hello world" {} PARSING RECORD-ORIENTED FILESParse a Unix /etc/passwd file, which consists of one entry per line, with each line consisting of a colon-separated list of fields: ## Read the file set fid [open /etc/passwd] set content [read $fid] close $fid ## Split into records on newlines set records [split $content "\n"] ## Iterate over the records foreach rec $records { SEE ALSOjoin(n), list(n), string(n) KEYWORDSlist, split, string
|