Function overview
Prototype
Before (
_text; _searchString; _occurrence; _include_boolean )
Parameters
_text
_searchString
_occurrence
_include_boolean
Description
Tags:
text parsing
extracts the beginning of a text, based on a search string and an occurrence number
occurrence can be positive (starting from the beginning of the text) or negative (starting from the end)
see also After, Between, and BetweenNext functions
Examples
Sample input
Before ( "abcd" ; _"c" ; 1 ; 0 )
Sample output
"ab"
Function code
/*
Before ( _text ; _searchString ; _occurrence ; _include_boolean )
by Fabrice Nordmann
v.2.1 Mar 2010
v.2, Mar 2007
v.1, Jan 2007
v2 adds inclusion boolean parameter.
extracts the beginning of a text, based on a search string and an occurrence number
occurrence can be positive (starting from the beginning of the text) or negative (starting from the end)
see also After, Between, and BetweenNext functions
*/
Case ( PatternCount ( _text ; _searchString ) ;
Let ( _occurrence = Case ( _occurrence = 0 ; 1 ; _occurrence )
;
Left ( _text ;
Position ( _text ; _searchString ; Case ( _occurrence < 0 ; Length ( _text ) ; 1 ) ; _occurrence ) - 1 + GetAsBoolean ( _include_boolean ) * Length ( _searchString )
)
))
// ===================================
/*
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/84
Prototype: Before( _text; _searchString; _occurrence; _include_boolean )
Function Author: Fabrice (http://www.fmfunctions.com/mid/37)
Last updated: 20 March 2010
Version: 1.2
*/
// ===================================
/*__LITBR__Before ( _text ; _searchString ; _occurrence ; _include_boolean )__LITBR____LITBR__by Fabrice Nordmann__LITBR__v.2.1 Mar 2010__LITBR__v.2, Mar 2007__LITBR__v.1, Jan 2007__LITBR____LITBR__v2 adds inclusion boolean parameter.__LITBR____LITBR__extracts the beginning of a text, based on a search string and an occurrence number__LITBR__occurrence can be positive (starting from the beginning of the text) or negative (starting from the end)__LITBR____LITBR__see also After, Between, and BetweenNext functions__LITBR__*/__LITBR____LITBR__Case ( PatternCount ( _text ; _searchString ) ;__LITBR__Let ( _occurrence = Case ( _occurrence = 0 ; 1 ; _occurrence )__LITBR__;__LITBR__Left ( _text ;__LITBR__Position ( _text ; _searchString ; Case ( _occurrence < 0 ; Length ( _text ) ; 1 ) ; _occurrence ) - 1 + GetAsBoolean ( _include_boolean ) * Length ( _searchString )__LITBR__)__LITBR__))__LITBR____LITBR__// ===================================__LITBR__/*__LITBR____LITBR__ This function is published on FileMaker Custom Functions__LITBR__ to check for updates and provide feedback and bug reports__LITBR__ please visit http://www.fmfunctions.com/fid/84__LITBR____LITBR__ Prototype: Before( _text; _searchString; _occurrence; _include_boolean )__LITBR__ Function Author: Fabrice (http://www.fmfunctions.com/mid/37)__LITBR__ Last updated: 20 March 2010__LITBR__ Version: 1.2__LITBR____LITBR__*/__LITBR__// ===================================