GetValueIndex ( )

Function stats

Average user rating
362
336
9999
Support
FileMaker 7.0 +
Date posted
04 August 2012
Version
1
Recursive function
Yes

Author Info
 Lewis Lorenz

1 functions

Average Rating None

author_avatar



 

Function overview

Prototype

GetValueIndex  ( valueList;   valueString;   matchCase;   occurrence )


Parameters

valueList  The list to search.


valueString  The value to search for.


matchCase  Boolean specifies whether the search is case sensitive.


occurrence  Require a specific valueString occurrence (a negative number causes backward search from the end of the valueList).


Description

Tags:  value list   occurrence   index   case sensitive  

Retrieve the index of the matching valueString in the valueList. Returns 0 if not found.
Optionally toggle case-sensitive searching by passing a boolean through matchCase.
Optionally search for specific valueString occurrence (a negative occurrence number causes backward search from the end of the valueList).

Examples

Sample input

ValueListIndex ("James¶Bill¶James¶Frank¶James¶Ed", "james", False, -2)


Sample output

3

 

Function code

Let ([ vlist = "¶" & valueList & "¶"; vtext = "¶" & valueString & "¶";
pos = If ( occurrence = 0; 0; Position( vlist; vtext; If ( occurrence < 0; Length ( vlist ); 1 ); If ( occurrence < 0; -1; 1 ) ) );
index = If ( pos; ValueCount ( Left ( vlist; pos ) ); 0 );
match = Exact ( GetValue ( valueList; index ); valueString );
occurrence = Case ( pos = 0; 0; matchCase; If ( match; occurrence + If ( occurrence > 0; -1; 1 ); occurrence); occurrence + If ( occurrence > 0; -1; 1 ) );
vlist = Case ( occurrence < 0; Left ( valueList; pos - 1 ); occurrence > 0; Right ( valueList; Length ( valueList ) - ( pos + Length ( valueString ) )); "" );
idx2 = If ( occurrence ≠ 0; GetValueIndex ( vlist ; valueString ; matchCase ; occurrence ); 0 );
index = Case ( occurrence < 0; idx2; occurrence > 0; If ( idx2 = 0; 0; index + idx2); index )];

index

)

/*
GetValueIndex (valueList, valueString, matchCase, occurrence)

by Lewis C. Lorenz.

9-20-2011: Created
9-22-2011: Updated.

Retrieve the index of the matching valueString in the valueList. Returns 0 if not found.
Optionally toggle case-sensitive searching by passing a boolean through matchCase.
Optionally search for specific valueString occurrence (a negative occurrence number causes backward search from the end of the valueList).

Examples:
ValueListIndex ("Alpha¶Bravo¶Charlie¶Echo", "charlie", False, 1) = 3
ValueListIndex ("Alpha¶Bravo¶Charlie¶Echo", "charlie", True, 1) = 0
ValueListIndex ("James¶Bill¶James¶Frank¶James¶Ed", "james", False, -2) = 3
*/

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/336

    Prototype: GetValueIndex( valueList; valueString; matchCase; occurrence )
    Function Author: Lewis Lorenz (http://www.fmfunctions.com/mid/362)
    Last updated: 04 August 2012
    Version: 1

*/
// ===================================

 

 

 

 

 

 

 

Top Tags

Text Parsing  (33)
List  (32)
Date  (28)
XML  (27)
Format  (23)
Sql  (22)
Dev  (20)
Debug  (17)
Interface  (15)
Layout  (15)
Text  (14)
Variables  (13)
Filter  (12)
Layout Objects  (11)
Design  (10)
Array  (8)