split.n
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:3k
- '"
- '" Copyright (c) 1993 The Regents of the University of California.
- '" Copyright (c) 1994-1996 Sun Microsystems, Inc.
- '"
- '" See the file "license.terms" for information on usage and redistribution
- '" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- '"
- '" RCS: @(#) $Id: split.n,v 1.3.18.1 2004/10/27 14:23:58 dkf Exp $
- '"
- .so man.macros
- .TH split n "" Tcl "Tcl Built-In Commands"
- .BS
- '" Note: do not modify the .SH NAME line immediately below!
- .SH NAME
- split - Split a string into a proper Tcl list
- .SH SYNOPSIS
- fBsplit fIstring fR?fIsplitCharsfR?
- .BE
- .SH DESCRIPTION
- .PP
- Returns a list created by splitting fIstringfR at each character
- that is in the fIsplitCharsfR argument.
- Each element of the result list will consist of the
- characters from fIstringfR that lie between instances of the
- characters in fIsplitCharsfR.
- Empty list elements will be generated if fIstringfR contains
- adjacent characters in fIsplitCharsfR, or if the first or last
- character of fIstringfR is in fIsplitCharsfR.
- If fIsplitCharsfR is an empty string then each character of
- fIstringfR becomes a separate element of the result list.
- fISplitCharsfR defaults to the standard white-space characters.
- .SH EXAMPLES
- Divide up a USENET group name into its hierarchical components:
- .CS
- fBsplitfR "comp.lang.tcl.announce" .
- fI=> comp lang tcl announcefR
- .CE
- .PP
- See how the fBsplitfR command splits on fIeveryfR character in
- fIsplitCharsfR, which can result in information loss if you are not
- careful:
- .CS
- fBsplitfR "alpha beta gamma" "temp"
- fI=> al {ha b} {} {a ga} {} afR
- .CE
- .PP
- Extract the list words from a string that is not a well-formed list:
- .CS
- fBsplitfR "Example with {unbalanced brace character"
- fI=> Example with \{unbalanced brace characterfR
- .CE
- .PP
- Split a string into its constituent characters
- .CS
- fBsplitfR "Hello world" {}
- fI=> H e l l o { } w o r l dfR
- .CE
- .SH "PARSING RECORD-ORIENTED FILES"
- Parse a Unix /etc/passwd file, which consists of one entry per line,
- with each line consisting of a colon-separated list of fields:
- .CS
- ## Read the file
- set fid [open /etc/passwd]
- set content [read $fid]
- close $fid
- ## Split into records on newlines
- set records [fBsplitfR $content "\n"]
- ## Iterate over the records
- foreach rec $records {
- ## Split into fields on colons
- set fields [fBsplitfR $rec ":"]
- ## Assign fields to variables and print some out...
- lassign $fields \
- userName password uid grp longName homeDir shell
- puts "$longName uses [file tail $shell] for a login shell"
- }
- .CE
- .SH "SEE ALSO"
- join(n), list(n), string(n)
- .SH KEYWORDS
- list, split, string