|
Seek (Function) In french: Cherche
MyArray is array of 0 string // Fill the array Add(MyArray, "WINDEV") Add(MyArray, "WEBDEV") Add(MyArray, "WINDEV and WEBDEV") // Find "WINDEV" ResSubscript is int ResSubscript = Seek(MyArray, asLinearFirst, "WINDEV") Info("The WINDEV string is found at subscript: " + ResSubscript) // Returns: "The WINDEV string is found at subscript: 1"
Syntax
Seeking an element in a one-dimensional array of simple elements Hide the details
<Result> = Seek(<Array name> , <Type of search> , <Sought value> [, <Start subscript>])
<Result>: Integer - Subscript of sought element,
- -1 if the element is not found in the array.
<Array name>: Array Name of Array variable to use. This array must be a one-dimensional array. This array can also correspond to an array of simple elements of an advanced variable. <Type of search>: Integer constant Type of search to perform: | | asBinary | Binary search. This search mode is fast but it must be used on an array sorted in ascending order, without duplicates (see ArraySort). | asLinear | Linear search. The search starts:- from the first element.
- from the value of the parameter <Start subscript>.
The search stops as soon as an element is found. | asLinearLast | Linear search from the last element. This constant must not be used if <Start subscript> is specified. | asLinearPrevious | Linear search for the previous element. This search is performed from the current position or the value of <Start subscript>. | asLinearFirst | Linear search from the first element. <Start subscript> is ignored when this constant is specified. | asLinearNext | Linear search for the next element. This search is performed from the current position or the value of <Start subscript>. | The type of search can be combined with one or more search options: | | tccLexicographicOrder | Array sorted according to the linguistic order. This option is useful for a dichotomous search and it has no effect on a linear search. This option can only be used on the arrays of character strings. | tccRespectNumeric | Array sorted according to the order of numeric values. This option is useful for a dichotomous search and it has no effect on a linear search. This option can only be used on the arrays of character strings. | tccIgnoreAccent | Search ignoring accented characters. This option can only be used on the arrays of character strings. | tccIgnoreCase | Search ignoring the case. This option can only be used on the arrays of character strings. | tccIgnoreSpace | Search regardless of the spaces at the beginning and end of strings. This option can only be used on the arrays of character strings. | Versions 20 and latertccIgnoreInsideSpace New in version 20tccIgnoreInsideSpace tccIgnoreInsideSpace | Searching without taking into account the spaces inside the chains. This option can only be used on the arrays of character strings. | tccIgnorePonctuationAndSpace | Searching without taking spaces and punctuation into account. This option can only be used on the arrays of character strings. | For a dichotomous search, the search options must be exactly the same as the options that were used to sort the array (see ArraySort). <Sought value>: Any type Value of element whose subscript is requested. <Start subscript>: Optional integer Start position for the search (linear search only). This parameter is not required for a binary search.
Seeking an element in a two-dimensional array of simple elements according to a column Hide the details
<Result> = Seek(<Array name> , <Type of search> , <Column> , <Sought value> [, <Start subscript>])
<Result>: Integer - Subscript of sought element,
- -1 if the element is not found in the array.
<Array name>: Array Name of Array variable to use. This array must be a two-dimensional array. This array can also correspond to a two-dimensional array of advanced type (sorting an xlsDocument variable according to the values of a column for example). <Type of search>: Integer constant Search to perform: | | asBinary | Binary search. This search mode is fast but it must be used on an array sorted in ascending order, without duplicates (ArraySort used on the search column). | asLinear | Linear search. The search starts:- from the first element.
- from the value of the parameter <Start subscript>.
The search stops as soon as an element is found. | asLinearLast | Linear search from the last element. This constant must not be used if <Start subscript> is specified. | asLinearPrevious | Linear search for the previous element. This search is performed from the current position or the value of <Start subscript>. | asLinearFirst | Linear search from the first element. This constant must not be used if <Start subscript> is specified. | asLinearNext | Linear search for the next element. This search is performed from the current position or the value of <Start subscript>. | The type of search can be combined with one or more search options: | | tccLexicographicOrder | Array sorted according to the linguistic order. This option is useful for a dichotomous search and it has no effect on a linear search. This option can only be used on the arrays of character strings.
| tccRespectNumeric | Array sorted according to the order of numeric values. This option is useful for a dichotomous search and it has no effect on a linear search. This option can only be used on the arrays of character strings. | tccIgnoreAccent | Search ignoring accented characters. This option can only be used on the arrays of character strings. | tccIgnoreCase | Search ignoring the case. This option can only be used on the arrays of character strings. | tccIgnoreSpace | Search regardless of the spaces at the beginning and end of strings. This option can only be used on the arrays of character strings. | Versions 20 and latertccIgnoreInsideSpace New in version 20tccIgnoreInsideSpace tccIgnoreInsideSpace | Searching without taking into account the spaces inside the chains. This option can only be used on the arrays of character strings. | tccIgnorePonctuationAndSpace | Searching without taking spaces and punctuation into account. This option can only be used on the arrays of character strings. | For a dichotomous search, the search options must be exactly the same as the options that were used to sort the array (see ArraySort). <Column>: Integer or character string - Simple array: Subscript of column where the search will be performed.
- Advanced array: Property for which the search must be performed. You also have the ability to use chained properties ("Border.Color" for example).
<Sought value>: Any type Value of element whose subscript or property is requested. <Start subscript>: Optional integer Start position for the search (linear search only). This parameter is not required for a binary search.
Seeking an element in a two-dimensional array of simple elements according to several columns Hide the details
<Result> = Seek(<Array name> , <Type of search> , <Columns> , <Sought value 1> [, <Sought value 2> [... [, <Sought value N>]]] [, <Start subscript>])
<Result>: Integer - Subscript of sought element,
- -1 if the element is not found in the array.
<Array name>: Array Name of Array variable to use. This array must be a two-dimensional array. This array can also correspond to a two-dimensional array of advanced type (sort performed on an xlsDocument variable according to the values of one or more columns for example). <Type of search>: Integer constant Search to perform. No binary search is available. | | asLinear | Linear search. The search starts:- from the first element
- from <Start subscript>
The search stops as soon as an element is found. | asLinearLast | Linear search from the last element. This constant must not be used if <Start subscript> is specified. | asLinearPrevious | Linear search for the previous element. This search is performed from the current position or the value of <Start subscript>. | asLinearFirst | Linear search from the first element. This constant must not be used if <Start subscript> is specified. | asLinearNext | Linear search for the next element. This search is performed from the current position or the value of <Start subscript>. | The type of search can be combined with one or more search options: | | tccLexicographicOrder | Array sorted according to the linguistic order. This option is useful for a dichotomous search and it has no effect on a linear search. This option is applied to all columns on which the search is performed. This option is useful for the arrays of character strings. | tccRespectNumeric | Array sorted according to the order of numeric values. This option is useful for a dichotomous search and it has no effect on a linear search. This option is applied to all columns on which the search is performed. This option is useful for the arrays of character strings. | tccIgnoreAccent | Search ignoring accented characters. This option is applied to all columns on which the search is performed. This option is useful for the arrays of character strings. | tccIgnoreCase | Search ignoring the case. This option is applied to all columns on which the search is performed. This option is useful for the arrays of character strings. | tccIgnoreSpace | Search regardless of the spaces at the beginning and end of strings. This option is applied to all columns on which the search is performed. This option is useful for the arrays of character strings. | Versions 20 and latertccIgnoreInsideSpace New in version 20tccIgnoreInsideSpace tccIgnoreInsideSpace | Searching without taking into account the spaces inside the chains. This option is applied to all columns on which the search is performed. This option is useful for the arrays of character strings. | tccIgnorePonctuationAndSpace | Searching without taking spaces and punctuation into account. This option is applied to all columns on which the search is performed. This option is useful for the arrays of character strings. | For a dichotomous search, the search options must be exactly the same as the options that were used to sort the array (see ArraySort). <Columns>: Character string (with quotes) - Simple array: List of columns where the search must be performed. The different columns must be separated by a semicolon. Example: "2;3" to perform a search on the columns 2 and 3.
- Advanced array: List of properties where the search must be performed. The properties must be separated by a semicolon.
<Sought value 1>: Any type Value of element whose subscript or property is requested. A value must be indicated for each column or property specified in <Columns>. <Sought value 2>: Any optional type Value of element whose subscript or property is requested. A value must be indicated for each column or property specified in <Columns>. <Sought value N>: Any optional type Value of element whose subscript or property is requested. A value must be indicated for each column or property specified in <Columns>. <Start subscript>: Optional integer Start position for the search (linear search only). This parameter is not required for a binary search.
Seeking an element in a one-dimensional array of structures, classes, advanced types or records Hide the details
<Result> = Seek(<Array name> , <Type of search> , <Sought members> , <Sought value 1> [, <Sought value 2> [... [, <Sought value N>]]] [, <Start subscript>])
<Result>: Integer - Subscript of sought element,
- -1 if the element is not found in the array.
<Array name>: Array Name of Array variable to use. This array must be a one-dimensional array. This array can be: - an array of classes,
- an array of structures,
No search can be performed in an array of structures. - an array of advanced types,
Versions 22 and later  an array of records. New in version 22  an array of records.   an array of records.
<Type of search>: Integer constant Type of search to perform: | | asBinary | Binary search. This search mode is fast but it must be used on an array sorted in ascending order, without duplicates (ArraySort). This search mode can also be used when performing a search on a single member. | asLinear | Linear search. The search starts:- from the first element
- from <Start subscript>
The search stops as soon as an element is found. | asLinearLast | Linear search from the last element. This constant must not be used if <Start subscript> is specified. | asLinearPrevious | Linear search for the previous element. This search is performed from the current position or the value of <Start subscript>. | asLinearFirst | Linear search from the first element. This constant must not be used if <Start subscript> is specified. | asLinearNext | Linear search for the next element. This search is performed from the current position or the value of <Start subscript>. | The type of search can be combined with one or more search options: | | tccLexicographicOrder | Array sorted according to the linguistic order. This option is useful for a dichotomous search and it has no effect on a linear search. This option is applied to all members on which the search is performed. This option is useful for the "character string" members. | tccRespectNumeric | Array sorted according to the order of numeric values. This option is useful for a dichotomous search and it has no effect on a linear search. This option is applied to all members on which the search is performed. This option is useful for the "character string" members. | tccIgnoreAccent | Search ignoring accented characters. This option is applied to all members on which the search is performed. This option is useful for the "character string" members. | tccIgnoreCase | Search ignoring the case. This option is applied to all members on which the search is performed. This option is useful for the "character string" members. | tccIgnoreSpace | Search regardless of the spaces at the beginning and end of strings. This option is applied to all members on which the search is performed. This option is useful for the "character string" members. | Versions 20 and latertccIgnoreInsideSpace New in version 20tccIgnoreInsideSpace tccIgnoreInsideSpace | Searching without taking into account the spaces inside the chains. This option is applied to all members on which the search is performed. This option is useful for the "character string" members. | tccIgnorePonctuationAndSpace | Searching without taking spaces and punctuation into account. This option is applied to all members on which the search is performed. This option is useful for the "character string" members. | For a dichotomous search, the search options must be exactly the same as the options that were used to sort the array (see ArraySort). <Sought members>: Character string (with quotes) - Structures and classes: Name of sought members. If several members are sought, their names must be separated by a semicolon. You also have the ability to chain the sought members (by using "." or ":" between the members). In a class, you also have the ability to perform a search on the class properties.
- Advanced types: Name of sought properties. If several properties are sought, their names must be separated by a semicolon. You also have the ability to chain the sought properties (by using "." or ":" between the properties). For example, "Border.Color".
Versions 22 and laterRecords: Name of sought items. If several items are sought, their names must be separated by a semicolon. You also have the ability to chain the sought items (by using "." or ":" between the properties). New in version 22Records: Name of sought items. If several items are sought, their names must be separated by a semicolon. You also have the ability to chain the sought items (by using "." or ":" between the properties). Records: Name of sought items. If several items are sought, their names must be separated by a semicolon. You also have the ability to chain the sought items (by using "." or ":" between the properties).
<Sought value 1>: Any type Value of element whose member or property is requested. A value must be indicated for each member specified in <Sought members>. <Sought value 2>: Any optional type Value of element whose member or property is requested. A value must be indicated for each member specified in <Sought members>. <Sought value N>: Any optional type Value of element whose member or property is requested. A value must be indicated for each member specified in <Sought members>. <Start subscript>: Optional integer Start position for the search (linear search only). This parameter is not required for a binary search.
Seeking the subscript of an object in a one-dimensional array (syntax for the data binding) Hide the details
<Result> = Seek(<Array name> , <Type of search> , <Sought object>)
<Result>: Integer - Subscript of the sought object,
- -1 if the object is not found in the array.
<Array name>: Array Name of Array variable to use. This array must be a one-dimensional array. This array can be an array of classes, dynamic classes, structures, dynamic structures, advanced types, dynamic advanced types. <Type of search>: Integer constant Type of search to perform: <Sought object>: Any type Instance of sought object. Remarks - This function cannot be used on the fixed arrays.
- This function can be used on the arrays of advanced variables.
- This function cannot be used on the array of "Dynamic objects".
- This function can be used on the arrays of typed objects.
- For example, no search can be performed in the following array:
t is array of 2 objects dynamic
- For example, a search can be performed in the following array:
t is array of 2 MyClass dynamic
- No search can be performed on an array of variants.
- No search can be performed on the Unicode strings.
  If the type of the search is dichotomous and if the array is not sorted, no WLanguage error will be displayed but the result of the search will be undefined.
This page is also available for…
|
|
|
| |
| | //Vou ensinar como Procurar um valor dentro array
tabListanumeros is array of 0 int ArrayAddLine(tabListanumeros,10) ArrayAddLine(tabListanumeros,5) ArrayAddLine(tabListanumeros,3) ArrayAddLine(tabListanumeros,1) //Coloca Array numa String
EDT_Texto = ArrayToString(tabListanumeros)
n_procura is int=Seek(tabListanumeros, asLinearFirst, EDT_PROCURA) IF n_procura=-1 THEN EDT_resultado="Nao Achou" ELSE EDT_resultado="Achou" END
// Blog com Video e Exemplo http://windevdesenvolvimento.blogspot.com.br/2016/12/aula-993-windev-array-005-seek.html https://www.youtube.com/watch?v=Q5yuh3bu8J8
|
|
|
|
| |
| |
| |
| |
| |
| |
| | |
| |