@Member in reverse

How to find the last position in a text list up to 99 elements.

View member feedback to this tip.

@Member finds a value's first position in a text list. This formula finds all positions of a string. It works for lists with up to 99 elements.

_listToSearch := "a":"b":"c":"b":
"b":"a":"c":"b"; 
_searchString := "c"; 
@if(@Elements(_listToSearch)=0;
@return(0);""); 
_digits:="0":"1":"2":"3":"4":"5":"
6":"7":"8":"9"; 
_0_to_99 := _digits *+ _digits; 
_1_to_99 := @Subset(_0_to_99; -99); 
_1_to_numOfElements:=@Subset
(_1_to_99; @Elements(_listToSearch)); 
_list1:= _listToSearch + _1_to_numOfElements; 
_list2 := _searchString + _1_to_numOfElements; 
_list3 := @Replace(_list1;_list2;""); 
_list4 := @Replace(_list1;@Trim(_list3);""); 
_positionsString:=@Replace(@Trim
(_list4);_list2; _1_to_numOfElements); 
_position :=@If(_positionsString="" ; 
       0; 
        @TextToNumber(_positionsString) 
); 
_position

MEMBER FEEDBACK TO THIS TIP

Another way, rather than trying to keep track of all those @Replace calls, is to use @Right:

_listToSearch := "a":"b":"c":"b":"b":"a":"c":"b";
_searchString := "c";
_digits:="0":"1":"2":"3":"4":"5":"6":"7":"8":"9";
_0_to_99 := _digits *+ _digits;
_1_to_99 := @Subset(_0_to_99; -99);
_1_to_numOfElements:=@Subset
(_1_to_99; @Elements(_listToSearch));
_list1:= _listToSearch + _1_to_numOfElements;

REM "<-- New code starts here -->";
_locs := @Trim(@Right(_list1; _searchString));
_position := @If(@Elements(_locs) = 0; 
@Replace(_locs; ""; "Not found");
@Subset(_locs; -1));
_position
-- SearchDomino.com member

**************************************************

I wished I'd had this formula about six months ago! (And why couldn't I come up with it myself!?!) This one is definitely a keeper! Thanks!

-- Jo R.

**************************************************

Using @Right instead of @Replace is not a correct substitution for this task:

If you start with the list
    _listToSearch := "a":"b":"xc":"b":"b":"a":"xc":"b";
you will get the same result as using
    _listToSearch := "a":"b":"c":"b":"b":"a":"c":"b"
-- Lothar F.

**************************************************

If you need to work on lists with more than 99 elements, just replace the list that is hold in var "_1_to_99" ("1":"2":.......:"99") with a list that is long enough for your needs; for example, "_1_to_999" ("1":"2":.......:"999")

This is all you need to change!

-- Joachim Rapp

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

This tip was submitted to the SearchDomino.com tip library by member Joachim Rapp. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

Dig Deeper on Lotus Notes Domino Formula Language

SearchWindowsServer

Search400

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/Search400.com community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury

SearchDataCenter

SearchContentManagement

Close