Srch: Difference between revisions
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
Srch(array-name$,[^]argument$[,row]) | Srch(array-name$,[^]argument$[,row]) | ||
The '''Srch''' [[internal function]] searches an [[array]] and returns the row number matching the argument. The argument must be the same data type (string or numeric) as the array. The optional "row" parameter defines the starting array element for the search. | The '''Srch''' [[internal function]] searches an [[arrays|array]] and returns the row number matching the argument. The argument must be the same data type (string or numeric) as the array. The optional "row" parameter defines the starting array element for the search. | ||
====Optional Case Insensitivity and Substring matching==== | ====Optional Case Insensitivity and Substring matching==== |
Revision as of 01:26, 15 January 2013
Srch(array-name,argument[,row])
OR
Srch(array-name$,[^]argument$[,row])
The Srch internal function searches an array and returns the row number matching the argument. The argument must be the same data type (string or numeric) as the array. The optional "row" parameter defines the starting array element for the search.
Optional Case Insensitivity and Substring matching
If argument$ begins with the caret ^, then the ^ is stripped and the search for argument$ in array-name$ becomes case insensitive.
For example:
00010 let a$(1)='abc' 00020 let a$(2)='def' 00030 print srch(mat a$,'^B')
Output:
1
Comments and Examples
When the search is unsuccessful, Srch returns -1 (unless option 56 is enabled, in which case srch would return a 0). In line 510 below, if STATES$ is a string array containing the 50 valid two-letter state abbreviations, then a data entry program could check whether the operator entered a correct abbreviation into the variable ST$ by the following:
500 LINPUT ST$ 510 If Srch(Mat States$,ST$) = -1 then goto 500
The example below will find the selected item in a combo box
500 combo_choice$=srch(mat array-name$,"^^")
IMPORTANT
Earlier versions of BR return 0 when SRCH doesn't find the desired argument in the array. Later versions return -1 in the same situation. In order to make you programs produce the same results regardless of the BR version, use the following logic:
00010 if not SRCH(mat array$, string_to_find$) > 0 then 00020 ! add the code for when the result is NOT found 00030 else 00040 ! add the code for when the result IS found 00050 end if
Related Functions
Technical Considerations
- If a match was not found, Srch will return -1.