pos()

Read(320) Label: pos,

Here’s how to use pos() function.

A .pos()

Description:

Get the position of a member in a sequence.

Syntax:

A.pos(x)

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.

Parameters:

A

A sequence object or an expression that returns one.

x

A member.

Options:

@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 sequence 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 sequence 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 sequence number or a sequence composed of sequence 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

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,3].pos@b(3)

Return null

Related functions:

A.pos(x)

A.psort()

A .pos( x )

Description:

Get the positions of sequence members in another sequence.

Syntax:

A.pos(x)

Note:

x is a sequence. The function returns integer sequence p which satisfies A(p)==x, and returns null if it cannot find the positions for all members of x.

Parameters:

A

A sequence

x

A sequence

Options:

@i

Return a monitonically increasing integer sequence p which satisfies A(p)==x

@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 functions:

A.pos()

A.psort()

pos()

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.

Parameters:

s1

The parent string where you want to search for the substring.

s2

Substring of interest.

begin

The position from which the search starts; the default search is from the beginning.

Options:

@z

Perform the search leftward starting from begin, while the search will be done rightward by default.

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