Position() function and multi-occurrence finding

Beginner

Use the occurrence parameter of Position() to find the second, third, or nth occurrence of a substring, enabling robust multi-delimiter text parsing.

What you'll learn

  • How the four arguments of Position() work together
  • How to find the second and nth occurrence of a delimiter
  • How to extract a specific segment from a delimited string
  • How to detect when a string contains a minimum number of occurrences

Position(text; searchString; start; occurrence) is FileMaker's workhorse for string location. Most developers use it to find the first occurrence, but the occurrence parameter lets you locate the second, third, or any nth match -- essential for parsing strings with repeated delimiters like CSV lines, URL parameters, or delimited codes.

1/3
1

Position() syntax review

Position(text; searchString; start; occurrence) -- text is the string to search, searchString is what to find, start is the character position to begin searching from, occurrence is which match to return.

FileMaker Script
// Find the first comma in a CSV string
Position ( "Smith, John, Sr." ; "," ; 1 ; 1 )  // -> 6

// Find the second comma (start from 1, occurrence = 2)
Position ( "Smith, John, Sr." ; "," ; 1 ; 2 )  // -> 12

// Search forward from position 7 for the next comma
Position ( "Smith, John, Sr." ; "," ; 7 ; 1 )  // -> 12

Sign in to track your progress and pick up where you left off.

Sign in to FM Dojo