Water 5-Common Data Types-String, Bytes, and Char | Water Contract<method key_of
item =req
same_case=true
start =0
end =null
include =vector_key
returns ="first"/> | |
See also: key_of, for_each
This functionality is like Java's indexOf method but can work on non-vectors as well as vectors,
returning the key of a field that has a given value.
Unlike Java's indexOf method, key_of uses "==" comparison instead of "equals" comparison.
That means the matched values must be THE same object, not just have the same parts.
Returns the integer position of item in the vector of _subject
or false if item is not in _subject <vector 97 98 99/>.<key_of 98/>
 | 1 |
<vector 97 98 99/>.<key_of 96/>
 | false |
key_of can be used to perform the "member" operation, i.e.
if the argument is a member of the vector of _subject then non-false will
be returned, otherwise false will be returned.
You can limit the section of _subject searched by supplying a 'start' and an 'end' index.
'start' defaults to 0 and 'end' defaults to null which means the length of _subject
'start' is inclusive, 'end' is exclusive.
If 'end' is more than the length of _subject then the length of _subject is used for 'end'.
The 'include' parameter determines which fields of _subject are looked at for value matches.
It is similar to the 'include' parameter in 'for_each'.
Its default value is vector_key which means that just the non-negative integer
fields are looked at.
If you give an include of 'string_key' you can look at the user fields:
<thing bcolor="red" weight=235/>.<key_of "red" include=string_key/>
 | "bcolor" |
<thing bcolor="red" weight=235/>.<key_of "red" include=string_key/>
 | "bcolor" |
See for_each for additional documentation on using include .
a wob
| Parameter key | Default value | Type |
| returns | "first" | string |
| determines the order of the search and what values are returned |
a wobreturns="first"
return the key of the first field that you find that matches the item value.
a wobreturns="last"
return the key of the last field that you find that matches the item value.
This may be used only when
include=vector_key. It starts the search from the
highest index field. The highest index field name that matches is returned.
a wobreturns="all"
return a vector of all the fields that match. When
_subject is a vector,
the returned vector will contain ascending integers.
If there are no matches, an empty vector will be returned.
The case_sensitive parameter determines how the comparison between a field value and
the item search for is made. If case_sensitive is false , the comparison between
two strings is made in a case insensitive way. The default is true .
Examples:
<vector "a" "b" "a"/>.<key_of "a" returns="last"/>
 | 2 |
<thing bcolor="red" fcolor="Red" acolor="green"/>.
<key_of "red" include=string_key returns="all"/> | <vector "bcolor"/>
|
© Copyright 2007 Clear Methods, Inc.