1lsearch(n)                   Tcl Built-In Commands                  lsearch(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       lsearch - See if a list contains a particular element
9

SYNOPSIS

11       lsearch ?options? list pattern
12_________________________________________________________________
13
14

DESCRIPTION

16       This  command  searches  the  elements  of  list  to see if one of them
17       matches pattern.  If so, the command returns the  index  of  the  first
18       matching  element  (unless  the options -all or -inline are specified.) │
19       If not, the command returns -1.  The option arguments indicates how the
20       elements of the list are to be matched against pattern and it must have
21       one of the following values:
22
23       -all   Changes the result to be the list of all  matching  indices  (or │
24              all matching values if -inline is specified as well.)
25
26       -ascii The  list  elements  are  to be examined as Unicode strings (the
27              name is for backward-compatability  reasons.)   This  option  is
28              only meaningful when used with -exact or -sorted.
29
30       -decreasing
31              The  list  elements are sorted in decreasing order.  This option
32              is only meaningful when used with -sorted.
33
34       -dictionary
35              The list elements are to be compared using dictionary-style com‐
36              parisons  (see  lsort for a fuller description).  This option is
37              only meaningful when used with -exact or -sorted, and it is only
38              distinguishable  from  the -ascii option when the -sorted option
39              is given, because values are only dictionary-equal when  exactly
40              equal.
41
42       -exact The  list  element  must contain exactly the same string as pat‐
43              tern.
44
45       -glob  Pattern is a glob-style pattern which is  matched  against  each
46              list element using the same rules as the string match command.
47
48       -increasing
49              The  list  elements are sorted in increasing order.  This option
50              is only meaningful when used with -sorted.
51
52       -inline
53              The matching value is returned instead of its index (or an empty │
54              string  if  no  value matches.)  If -all is also specified, then │
55              the result of the  command  is  the  list  of  all  values  that │
56              matched.
57
58       -integer
59              The  list  elements are to be compared as integers.  This option
60              is only meaningful when used with -exact or -sorted.
61
62       -not   This negates the sense of the match, returning the index of  the │
63              first non-matching value in the list.
64
65       -real  The  list  elements are to be compared as floating-point values.
66              This option is only meaningful when used with -exact or -sorted.
67
68       -regexp
69              Pattern is treated as a regular expression and  matched  against
70              each  list  element  using  the rules described in the re_syntax
71              reference page.
72
73       -sorted
74              The list elements are in sorted order.  If this option is speci‐
75              fied,  lsearch  will use a more efficient searching algorithm to
76              search list.  If no other options are specified, list is assumed
77              to  be sorted in increasing order, and to contain ASCII strings.
78              This option is mutually exclusive with -glob and -regexp, and is
79              treated  exactly like -exact when either -all, or -not is speci‐
80              fied.
81
82       -start index
83              The list is searched starting at position index.  If  index  has │
84              the  value  end,  it refers to the last element in the list, and │
85              end-integer refers to the last element in  the  list  minus  the │
86              specified integer offset.
87
88       If  option  is  omitted then it defaults to -glob.  If more than one of
89       -exact, -glob, -regexp, and -sorted is specified, whichever  option  is
90       specified  last takes precedence.  If more than one of -ascii, -dictio‐
91       nary, -integer and -real is specified, the option specified last  takes
92       precedence.   If more than one of -increasing and -decreasing is speci‐
93       fied, the option specified last takes precedence.
94
95

EXAMPLES │

97              lsearch {a b c d e} c => 2
98              lsearch -all {a b c a b c} c => 2 5
99              lsearch -inline {a20 b35 c47} b* => b35
100              lsearch -inline -not {a20 b35 c47} b* => a20
101              lsearch -all -inline -not {a20 b35 c47} b* => a20 c47
102              lsearch -all -not {a20 b35 c47} b* => 0 2
103              lsearch -start 3 {a b c a b c} c => 5
104
105

SEE ALSO

107       foreach(n), list(n),  lappend(n),  lindex(n),  linsert(n),  llength(n), │
108       lset(n), lsort(n), lrange(n), lreplace(n)
109
110

KEYWORDS

112       list, match, pattern, regular expression, search, string
113
114
115
116
117Tcl                                   8.4                           lsearch(n)
Impressum