Manage Learn to apply best practices and optimize your operations.

Nth position of a list

This tip describes how to get to a specific list item.

View member feedback to this tip.

It is easy to retrieve the first and last element of a list, but how do you return the nth position of a list?

The @Subset function can return the 1st position, the last position and X number of items in the list, but it can't return the nth value in the list.

The following code is an example of how to return the nth position of a text list.

First, make sure that your list actually contains at least the correct number of elements. Next, you use @Subset to return N number of elements. Finally, you grab the last element in that shortened list that corresponds to the element that you were looking for.


 
N := 10;
@If(@Elements(List) >= N; 
@Subset(@Subset
(List; N); -1); 
      ""
)
  

MEMBER FEEDBACK TO THIS TIP

I used to use this technique all the time. Then I learned about the @GetMembers function introduced in R5. It is undocumented in R5, but is supposed to be documented in ND6.

The @GetMembers function gets a member from a list. The first parameter is the list and the second is a number corresponding to the position of the list member you want to get. Beats the @Subset(@Subset(list; n);-1) function in clarity and simplicity because you don't have to do any error checking. For n = 0 the nested @Subset method generates an error for which you need to trap. The @GetMembers function, however, simply returns a null value for n <= 0. Search for @GetMembers in the "Notes/Domino 4 and 5 Forum" on the Lotus Developer Domain Web site for more information.

-- Gardner R.


Do you have comments of your own? Let us know.

Dig Deeper on Lotus Notes Domino Formula Language

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close