Hi,I wanted to find out how to count number of times a value is repeated in a list using formula language
e.g “pen”:“pencil”:“pen”:“rubber”:“pen”
I know if could propable use a for loop, but wanted to know if there is any other way.
Thanks,
Goutham
Hi,I wanted to find out how to count number of times a value is repeated in a list using formula language
e.g “pen”:“pencil”:“pen”:“rubber”:“pen”
I know if could propable use a for loop, but wanted to know if there is any other way.
Thanks,
Goutham
Subject: in formula languare how to count the number of times a value is repeated in a list
There are a number of different ways. I personally have a penchant for @replace i.e.
thingToCount:=“pen”;
pencilCaseContents:=“pen”:“pencil”:“pen”:“rubber”:“pen”;
Mark what you want and remove everything else approach:
starContents:=@replace(pencilCaseContents;thingToCount;“*”+thingToCount);
justThingsToCount:=@trim(@right(starContents;“*”));
numberOfThings:=@if(justThingsToCount=“”;0;@elements(justThingsToCount));
Another approach is to remove what you want to count, and display the difference i.e.
…
thingsNotWanted:=@trim(@replace(pencilCaseContents;thingToCount;“”));
numberOfThings:=@if(thingsNotWanted=“”;@elements(pencilCaseContents);@elements(pencilCaseContents) - @elements(thingsNotWanted))
HTH - Rufus.
Subject: RE: in formula languare how to count the number of times a value is repeated in a list
I would agree that @Replace is usually the way to go, although in Notes 6 you can also use @Transform
thingToCount:=“pen”;
pencilCaseContents:=“pen”:“pencil”:“pen”:“rubber”:“pen”;
numberOfThings := @Elements(@Transform(pencilCaseContents; “x”; @If(@IsMember(x; thingToCount); x; @Nothing)));
If you want to see a bit more on how @Transform can be used, see Rocky Oliver’s The Elusive @Transform, and my follow up: Top That, Rocky!
Subject: RE: in formula languare how to count the number of times a value is repeated in a list
Hi:Thank you all very much for the replies. I know know number of ways to do this.
Thanks,
Subject: in formula languae how to count the number of times a value (a number)is repeated in a list
Does anyone know how to count the number of times a value (a number) is repeated in a Column?
I want to know how many times the same number is in a column and print a message thats says i.e. “the number 4 is repeated 10 times, the number 43 is repeated 2 times” … and so on"
Regards,
Subject: in formula languare how to count the number of times a value is repeated in a list
How about this?
list := “pen”:“pencil”:“pen”:“rubber”:“pen”;
@Elements(@Unique(list));
HTH / Nick
Subject: in formula languare how to count the number of times a value is repeated in a list
Hi Vikram,I suggest you read up the formula language and list handling in particular, since it is a very basic skill you need.
You can use @Elements or @Count.
Hth
stw
Subject: RE: in formula languare how to count the number of times a value is repeated in a list
Stephan,
I think you misread the original question. He’s not after the number of elements in a list, but the number of times a particular item is repeated in a list. IMHO this isn’t a very basic skill and I quite often use this type of problem as an interview question to sort out the experienced developers from the more modern “lotusscript kiddies”.
Rufus.