Between ( )

Function stats

Average user rating
3.0000
37
89
9999
Support
FileMaker 8.0 +
Date posted
01 December 2008
Last updated
15 May 2009
Version
Recursive function
No

Author Info
 Fabrice

74 functions

Average Rating 4.4

author_avatar



 

Function overview

Prototype

Between  ( _text;   _searchString1;   _occurrence1;   _include1_boolean;   _searchString2;   _occurrence2;   _include2_boolean )


Parameters

_text  


_searchString1  


_occurrence1  


_include1_boolean  


_searchString2  


_occurrence2  


_include2_boolean  


Description

Tags:  text parsing  

extracts the middle of a text in between delimiters, based on a search strings and an occurrence numbers
occurrences can be positive (starting from the beginning of the text) or negative (starting from the end)

see also Before After, and BetweenNext functions

Examples

Sample input

Between ("/abc/def/ghi/" ; "/" ; 2 ; 1 ; "/" ; -2 ; 0 )


Sample output

/def

 

Function code

/*
Between ( _text ; _searchString1 ; _occurrence1 ; _include1_boolean ; _searchString2 ; _occurrence2 ; _include2_boolean)

by Fabrice Nordmann
v.2, Mar 2007
v.1, Jan 2007

v.2 adds inclusion boolean parameters

extracts the middle of a text in between delimiters, based on a search strings and an occurrence numbers
occurrences can be positive (starting from the beginning of the text) or negative (starting from the end)

see also Before After, and BetweenNext functions

eg.
Between ("/abc/def/ghi/" ; "/" ; 2 ; 1 ; "/" ; -2 ; 0 ) = "/def"
*/
Let ([
_occurrence1 = Case ( _occurrence1 = 0 ; 1 ; _occurrence1 )
; _occurrence2 = Case ( _occurrence2 = 0 ; 1 ; _occurrence2 )
; _p1= Position ( _text ; _searchString1 ; Case ( _occurrence1 < 0 ; Length ( _text ) ; 1 ) ; _occurrence1 ) + not GetAsBoolean ( _include1_boolean ) * Length ( _searchString1 )
; _p2= Position ( _text ; _searchString2 ; Case ( _occurrence2 < 0 ; Length ( _text ) ; 1 ) ; _occurrence2 ) + GetAsBoolean ( _include2_boolean ) * Length ( _searchString2 )

]
;
Middle ( _text ; _p1 ; _p2 - _p1 )
)

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

    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/89

    Prototype: Between( _text; _searchString1; _occurrence1; _include1_boolean; _searchString2; _occurrence2; _include2_boolean )
    Function Author: Fabrice (http://www.fmfunctions.com/mid/37)
    Last updated: 15 May 2009
    Version: 1.2

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

 

Comments

BruceR
20 February 2009



Doesn't work for me, seems like _p2 is incorrect. When this part is changed as follows it works for me:
Case ( _occurrence2 < 0 ; Length ( _text ) ; _p1 )
 Bug report
Fabrice
20 February 2009



Hi Bruce, and thanks for your comment.
I can't find a case where it wouldn't work, have you kept an example?

Thanks !
  General comment
BruceR
20 February 2009



I'm a little surprised you haven't run into the problem. My problem was parsing Geoff Coffey's dictionary functions. They look like this:
<:TBL:=EXPENSE:><:FMPID:=000619:><:Category:=Housing:><:Amount:=35:>
Without the mods, if I used "<:Cat" as search string 1 and ":>" as search string 2, it would not work because your CF would find the occurence of searchstring 2 in the text BEFORE search string 1. The search for string 2 MUST start after the position of string 1.
(Edited by BruceR on 20/02/09 )
 Bug report
Fabrice
20 February 2009



Oh! this !
then it may be a documentation issue, because what you want is precisely what BetweenNext is doing http://www.fmfunctions.com/fname/betweennext
Indeed I use it far more often than Between.
(Edited by Fabrice on 20/02/09 )
  General comment

 

 

 

 

 

Top Tags

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