Brian Dunning's FileMaker Custom Functions

cf_getElementNo ( SearchString ; ElementList )

Get the line number of sought-after element in a list

  Average rating: 4.4 (34 votes) Log in to vote

Klemens Müller   Klemens Müller
Klemens Müller
http://www.klemenso.de

Share on Facebook Share on Twitter

  Sample input:
cf_getElementNo( "gamma" ; "Alpha¶Beta¶Gamma¶Delta¶Epsilon" )
  Sample output:
3

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Determines the number of first occurenc of the sought-after element in a list of elements

 

Comments

Oliver Reid   Oliver Reid, CT, USA
Feb 28, 2009
I believe this will not work if a an earlier list element contains a later one:


e.g.,

firstgamma
gamma

and you search for 'gamma'
 
Oliver Reid   Oliver Reid, CT, USA
Feb 28, 2009
On reflection I suggest this change:

fpos = Position( ¶&clist&¶ ; ¶&spos&¶ ; 1 ; 1 ) + Length( spos )+1 ;
 
John Jackson   John Jackson, Santa Rosa CA USA
Aug 22, 2010
This won't work if SearchString isn't in ElementList in the first place; it will return a value anyways.
 
John Jackson   John Jackson, Santa Rosa CA USA
Aug 22, 2010
Here's a revised version:
Parameters: element_list, search_string

Let( [
s_pos = Position ( ¶&element_list&¶ ; ¶&search_string&¶ ; 1 ; 1 ) ;
f_pos = s_pos + Length ( search_string ) - 1 ;
f_list = Middle ( element_list ; 1 ; f_pos ) ;
index = ValueCount ( f_list )
] ;
If ( s_pos ;
index ;
0
)
)
 
Edward Souza   Edward Souza, Sao Paulo, BR
Sep 12, 2010
Hello, all,

Well done, Mr. Jackson. Thanks for sharing. :-)
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 15 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: