Programmer Guide/Command Reference/FIND: Difference between revisions

From STX Wiki
Jump to navigationJump to search
m (1 revision: Initial import)
No edit summary
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
==FIND==
The <code>FIND</code> command searches a table item for a particular entry and returns the zero-based index of this entry (if found), or the empty string (if unfound, eh, not found). Note that the <code>FIND</code> command can only be used with simple tables, and with string and name fields of extended tables.


The <code>FIND</code> command searches a table item for a particular entry and returns this entry's index (if found). The FIND command can only be used with simple tables or the extended table string/name fields.
#pos := FIND <var>table entry field</var> [ <var>mask taggedonly respectcase</var> ]


<code>#pos := FIND <var>table entry field</var> [<var>mask</var> <var>tag case</var>]</code>
;<var>table</var>: the name of the table item to search
 
;<var>entry</var>: the zero-based index of the item where the search should start, the asterisk, <code>*</code> (or, obviously, the index 0) indicating that the whole table is to be searched
-> #pos = 'entryindex' or empty if not found
;<var>field</var>: for an extended table, this has to be the zero-based index, or the name of, of the string field, or the name field, to be searched. For simple tables, this parameter is ignored (but has to be present!), and should be set to <code>*</code>.
 
;<var>mask</var>: the search mask (wildcards are possible)
;<var>table</var>
;<var>taggedonly</var>: if set to <code>1</code>, only ''tagged'' entries will be searched. If set to <code>1</code> (which is the default), ''all'' entries of the table will be searched.
 
;<var>respectcase</var>: if set to <code>0</code>, the search will be case-insensitive (this is the default). If set to <code>1</code>, the search will case-sensitive.
:The name of the table item to search.
[macro FindStringInTable]
 
#t := new table *
;<var>entry</var>
$#t * 'The big red apple was very juicy'
 
$#t * 'The blue waves were mesmerizing'
:<code>*</code> for all entries or the index from which to start searching.
$#t * 'The green man said - "You are coming with me"'
 
$#t * 'The red dwarf star was a million miles away'
;<var>field</var>
#searchStr := 'red'
 
do forever
:Index or name of string/name field. This parameter is ignored for simple tables and should be set to <code>*</code>.
    #i := find $#t '$#i' '*' '*$#searchStr*'
 
    if '$rc' != 0 break
;<var>mask</var>
    um 'The table entry $#i ($#t[$#i]) contains the word "$#searchStr"'
 
end
:The search mask (wildcards are possible).
delete /Var #t
 
exit
;<var>tag</var>
 
:Search all (<code>0</code>) or tagged (<code>1</code>) fields. The default is <code>0</code>.
 
;<var>case</var>
 
:Ignore (<code>0</code>) or respect (<code>1</code>) case. The default is <code>0</code>.
 
<pre>
[macro FindStringInTable]
#t := new table *
$#t * 'The big red apple was very juicy'
$#t * 'The blue waves were mesmerizing'
$#t * 'The green man said - "You are coming with me"'
$#t * 'The red dwarf star was a million miles away'
#searchStr := 'red'
do forever
    #i := find $#t '$#i' '*' '*$#searchStr*'
    if '$rc' != 0 break
    um 'The table entry $#i ($#t[$#i]) contains the word "$#searchStr"'
end
delete $#t
exit
</pre>

Revision as of 15:36, 6 April 2011

The FIND command searches a table item for a particular entry and returns the zero-based index of this entry (if found), or the empty string (if unfound, eh, not found). Note that the FIND command can only be used with simple tables, and with string and name fields of extended tables.

#pos := FIND table entry field [ mask taggedonly respectcase ]
table
the name of the table item to search
entry
the zero-based index of the item where the search should start, the asterisk, * (or, obviously, the index 0) indicating that the whole table is to be searched
field
for an extended table, this has to be the zero-based index, or the name of, of the string field, or the name field, to be searched. For simple tables, this parameter is ignored (but has to be present!), and should be set to *.
mask
the search mask (wildcards are possible)
taggedonly
if set to 1, only tagged entries will be searched. If set to 1 (which is the default), all entries of the table will be searched.
respectcase
if set to 0, the search will be case-insensitive (this is the default). If set to 1, the search will case-sensitive.
[macro FindStringInTable]
#t := new table *
$#t * 'The big red apple was very juicy'
$#t * 'The blue waves were mesmerizing'
$#t * 'The green man said - "You are coming with me"'
$#t * 'The red dwarf star was a million miles away'
#searchStr := 'red'
do forever
    #i := find $#t '$#i' '*' '*$#searchStr*'
    if '$rc' != 0 break
    um 'The table entry $#i ($#t[$#i]) contains the word "$#searchStr"'
end
delete /Var #t
exit

Navigation menu

Personal tools