Here’s how to use pos() functions.
Description:
Get the position of a member in a sequence.
Syntax:
A.pos(x,k)
Note:
The function locates member x in sequence A where x may appear repeatedly. Return null if the member cannot be found; return different values according to different options and return the position of the first-found member if no option is present. When parameter k is present, begin the search from the kth member.
Parameter:
A |
A sequence object or an expression that returns one |
x |
A member |
k |
Search from the kth member |
Option:
@b |
Use the binary search to query the location. In this case A is by default an ordered sequence. Both increasing and decreasing are applicable. |
@a |
Return an n-integer sequence consisting of ordinal numbers of all the members that fulfill the query condition. |
@z |
Perform the search backwards from the last member; by default perform the search from the first member. |
@s |
With an ordered A and the binary search, return the position of x if it is a member of A; otherwise, return the opposite number for the ordinal number representing the position where x can be inserted sequentially. |
@p |
Find position of the sequence x, which needs to be treated as a single value, in A, which, in this case, is a sequence of sub-sequences. |
@n |
Return the result of the length of A plus 1 if x cannot be found in A. This option and @a are mutually exclusive. |
Return value:
A ordinal number or a sequence composed of ordinal numbers
Example:
|
A |
|
1 |
=[1,2,8,4,5,6,7,8] |
|
2 |
=A1.pos(8) |
3 |
3 |
=A1.pos@a(8) |
[3,8] |
4 |
=A1.pos@z(8) |
8 |
5 |
=A1.pos@az(8) |
[8,3] |
6 |
=A1.pos@z(9) |
null |
7 |
=[1,2,3,4,5,6,7,8].pos@b(5) |
5 |
8 |
=[1,2,4,5,6,7,8].pos@s(3) |
-3 |
9 |
=[[6,2,1,4,6,3,7,8],[1,4,6]].pos@p([1,4,6]) |
2 |
10 |
=[6,2,1,4,6,3,7,8].pos@n(5) |
9 |
11 |
=[6,2,1,4,6,3,7,8].pos(6,3) |
5 |
Note:
If A is not ordered, then options @b and @s should not be used, or they may bring about the incorrect results. For example: [7,6,1,2].pos@b(3) returns null.
Related function:
Description:
Get the positions of sequence members in another sequence.
Syntax:
A.pos(x)
Note:
The function gets positions of members in sequence x in sequence A. and returns null if it cannot find the positions for all members of x.
Parameter:
A |
A sequence |
x |
A sequence |
Option:
@i |
Return a monitonically increasing integer sequence |
@c |
Return the position in which sequence x first appears in A. By doing so, the position of sub-sequence x in sequence A can be located. If x is not the sub-sequence of A, then return null. |
@b |
Use the binary search to query the location. In this case A is by default assumed as an ordered sequence. Both Increasing and decreasing are applicable |
Return value:
A monotonically increasing integer sequence or an integer sequence
Example:
[6,2,1,4,6,3,7,8].pos@i([1,4,6]) |
[3,4,5], which is a monitonically increasing integer sequence |
[6,2,1,4,6,3,7,8].posi([1,4,6]) |
[3,4,1], which is an integer sequence |
[1,2,3,4,6,7,8].pos@b([3,1,4,6]) |
[3,1,4,5] |
[2,1,4,6,3,7,8].pos@i([8,4,6]) |
null |
[2,1,4,6,3,7,8,4,6,1].pos@c([4,6]) |
3 |
Related function:
Description:
Get the position of a substring in its parent string.
Syntax:
pos(s1, s2{, begin})
Note:
The function finds the position of substring s2 in the parent string s1, which starts from the position begin, and returns null if the substring cannot be found.
Parameter:
s1 |
The parent string where you want to search for a substring |
s2 |
Substring of interest |
begin |
The position from which the search starts; the default search is from the beginning |
Option:
@z |
Perform the search leftward starting from begin, while the search will be done rightward by default |
@c |
Case-insensitive |
@h |
Search for the substring at the beginning of the parent string by ignoring parameter begin |
@q |
Skip quoted strings when searching the parent string |
Return value:
Integer type
Example:
pos("abcdef","def") |
4 |
pos("abcdefdef","def",5) |
7 |
pos("abcdef","defa") |
(null) |
pos@z("abcdeffdef","def",7) pos("abcdeffdef","def",7) |
4 8 |
pos@c("abcdef","Def") |
4; @c option makes case-insensitive |
pos ("a'b'cbe","b") |
3 |
pos@q("a'b'cbe","b") |
6; use @q option to skip quoted strings |