Equinox Online Help - Language Reference - A to Z

Home

ArraySearchNext

Applies to
SyntaxArraySearchNext ArrayExpression, PatternExpression, [StartItem, LengthItem, SearchExpression, ColumnExpression, IndexItem1, IndexItem2, IndexItem3, IndexItem4]
Action[Statement] Searches for a string within a string array.
ScopeUsable anywhere.
Notes

This statement searches for the string PatternExpression, inside all the strings in ArrayExpression. The ArraySearchNext statement uses the start and index parameters returned by a previous ArraySearch statement as the place to start searching from.

You can include the following special characters in PatternExpression:

  • * Wildcard: matches any number of characters
  • ? Wildcard: matches any single character
  • \n Matches an end of line character
  • \t Matches a tab character
  • \* Matches an asterisk character
  • \? Matches a question mark character
  • \\ Matches a back-slash character

The fifth argument, SearchExpression, can take one of the following values:

  • 0 Match case, interpret special characters, match whole item only, search forwards
  • 1 Ignore case, interpret special characters, match whole item only, search forwards
  • 2 Match case, ignore special characters, match whole item only, search forwards
  • 3 Ignore case, ignore special characters, match whole item only, search forwards
  • 4 Match case, interpret special characters, match part of item, search forwards
  • 5 Ignore case, interpret special characters, match part of item, search forwards
  • 6 Match case, ignore special characters, match part of item, search forwards
  • 7 Ignore case, ignore special characters, match part of item, search forwards
  • 8 Match case, interpret special characters, match whole item only, search backwards
  • 9 Ignore case, interpret special characters, match whole item only, search backwards
  • 10 Match case, ignore special characters, match whole item only, search backwards
  • 11 Ignore case, ignore special characters, match whole item only, search backwards
  • 14 Match case, ignore special characters, match part of item, search backwards
  • 15 Ignore case, ignore special characters, match part of item, search backwards

If you omit SearchExpression, then by default the value 0 is used

Exact case dictates that the two strings must be the same case to match. Any case ignores the case differences.

Special characters sometimes occur in the target, for example back-slash occurs in operating system file paths. You can choose to ignore special characters in the PatternExpression, and treat them as literal characters.

Match part of an item means a sliding search, for example, searching for "asdf" in "this asdf string" returns true.

If PatternExpression is not matched, SysError is set to a nonzero value. Otherwise it is set to zero, the position of its first character is returned in StartItem, and the length of the matching portion of StringExpression is returned in LengthItem (if it is included). This is useful if you include wildcard characters in PatternExpression.

ColumnExpression specifies the element in the rightmost dimension that is searched in multi-dimensional arrays. If omitted or zero, every element is searched.

If the string is matched, the index in each array dimension is returned in the four final parameters. Note that in order for ArraySearchNext to work, you must supply an argument to receive the array index for each significant dimension in the array, and the start parameter if doing a partial search.

CategoryArrays
See Also ArrayFind, ArrayFindNext, ArrayGetDimensions, ArraySearch, ArraySetDimensions, ArraySort, ArrayNeg, ArrayNot, Vector, VectorSize
Example

This example shows the effect of different values of SearchExpression.

string vs[]

vs="Hello","world","this","is","a","string","array",\
"searchable","for","Hello","World","not","hello or hello",\
"world"

PrintDevice ""

lpSearch "Hello", 0
lpSearch "hello", 1
lpSearch "h*l", 5
lpSearch "hello", 15

procedure lpSearch string whatfor, int how
int start, length, idx

print "Searching for", whatfor, how
ArraySearch vs, whatfor, start, length, how,, idx

while SysError = 0
print idx, start, length, vs[idx]
ArraySearchNext vs, whatfor, start, length, how,, idx
end while

print
end procedure | lpSearch

This example searches one column of a multicolumn array.

string ss[2][3][4]
int idx1, idx2, idx3
int start, length
int column, how
string whatfor

PrintDevice ""

ss="Hello", "world", "this and that and the other", "is",\
"a", "string", "array", "searchable",\
"for", "Hello", "World", "not",\

\

"hello or hello", "world", "and", "*even",\
"some?", "special", "characters", "hello",\
"it's", "med", "and", "End"

how = 7
column = 3
whatfor = "and"

ArraySearch ss, whatfor, start, length, how, column, idx1, idx2, idx3

while SysError = 0
print idx1;":";idx2;":";idx3, start, length, ss[idx1][idx2][3]
ArraySearchNext ss, whatfor, start, length, how, column, idx1, idx2, idx3
end while