Brian Dunning's FileMaker Custom Functions

ListIndex ( list ; string ; matchcase )

Seaches a list and returns the indexnumber if found

  Average rating: 4.5 (33 votes) Log in to vote

Theo Ros   Theo Ros - Show more from this author

Share on Facebook Share on Twitter

  Sample input:
ListIndex ( "John¶Paul¶George¶Ringo" ; "ringo" ; False )
  Sample output:
4

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

Searches a Return delimited list 'list' for the occurrance of the given value.
Returns the 1-based indexnumber if found, 0 if value is not in the list.

Syntax: ListIndex ( list ; value ; matchcase )

In: list - the return delimited list to search
string - the string to look for in the item
matchcase - if True, the list is searched Case Sensitive
if False, a Case Insensitive search is performed

Return type: Number

 

Comments

Peter Sijmons   Peter Sijmons, Szienz
Mar 10, 2014
list has become a reserved word in FMP13 and can no longer be used as param
 
Luc Thomaere   Luc Thomaere
Apr 9, 2021
This function gives wrong results when searching for values that are substrings of other values:
ListIndex ( "John¶Paula¶George¶Ringo¶Paul" ; "Paul" ; False ) doesn't give 5

Better is:
(parameters: MyList, MyValue)

Let (
[
marker = "@*!|" ;
t = Substitute ( "¶" & ListID & "¶" ; "¶" & ID & "¶" ; "¶" & marker & "¶") ;
t = If ( Left ( t ; 1 ) <> "¶" ; "¶" & t ; t ) ;
pos = Position ( t ; marker ; 1 ; 1 ) ;
index = PatternCount ( Left ( t ; pos ) ; "¶" )
] ;
index )
 
Luc Thomaere   Luc Thomaere
Apr 9, 2021
Correction (with right parameter names):

Let (
[
marker = "@*!|" ;
t = Substitute ( "¶" & MyList & "¶" ; "¶" & MyValue & "¶" ; "¶" & marker & "¶") ;
t = If ( Left ( t ; 1 ) <> "¶" ; "¶" & t ; t ) ;
pos = Position ( t ; marker ; 1 ; 1 ) ;
index = PatternCount ( Left ( t ; pos ) ; "¶" )
] ;
index )
 

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 20 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: