Function overview
Prototype
BetweenNext (
_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)
The second string will be found only after the first one.
Both string can be included or excluded with boolean parameters.
Examples
Sample input
BetweenNext ( "A 1234567890 X B 1234567890 X C 1234567890 X" ; "B" ; 1 ; 1 ; "X" ; 1 ; 0 )
Sample output
B 1234567890
Function code
/*
BetweenNext ( _text ; _searchString1 ; _occurrence1 ; _include1_boolean ; _searchString2 ; _occurrence2 ; _include2_boolean )
by Fabrice Nordmann
v.1.5, Jan 2009
bug fix with short searchString
optimisation
v.1.1.1, Apr 2008
bug fix : if string2 was in string1, result would be erroneous
v.1.1, Feb 2008
returns empty if searchString1 is not found
v.1, Mar 2007
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)
The second string will be found only after the first one.
Both string can be included or excluded with boolean parameters.
e.g : BetweenNext ( "A 1234567890 X B 1234567890 X C 1234567890 X" ; "B" ; 1 ; 1 ; "X" ; 1 ; 0 )
= "B 1234567890 "
see also Between, Before and After functions
*/
Let ([
_occurrence1 = Case ( _occurrence1 = 0 ; 1 ; _occurrence1 )
; _occurrence2 = Case ( _occurrence2 = 0 ; 1 ; _occurrence2 )
; _lenStr1 = Length ( _searchString1 )
; _p1= Position ( _text ; _searchString1 ; Case ( _occurrence1 < 0 ; Length ( _text ) ; 1 ) ; _occurrence1 )
; _rightText = Replace ( _text ; 1 ; _p1 + _lenStr1 - 1 ; "" )
; _p2= Position ( _rightText ; _searchString2 ; Case ( _occurrence2 < 0 ; Length ( _rightText ) ; 1 ) ; _occurrence2 )
; _content = Left ( _rightText ; _p2 - 1 )
]
;
Case ( _p1 and _p2
; Case ( _include1_boolean ; _searchString1 ) & _content & Case ( _include2_boolean ; _searchString2 )
)
)
// ===================================
/*
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/87
Prototype: BetweenNext( _text; _searchString1; _occurrence1; _include1_boolean; _searchString2; _occurrence2; _include2_boolean )
Function Author: Fabrice (http://www.fmfunctions.com/mid/37)
Last updated: 02 December 2010
Version: 2.2
*/
// ===================================
/*__LITBR__BetweenNext ( _text ; _searchString1 ; _occurrence1 ; _include1_boolean ; _searchString2 ; _occurrence2 ; _include2_boolean )__LITBR____LITBR__by Fabrice Nordmann__LITBR__v.1.5, Jan 2009__LITBR__ bug fix with short searchString__LITBR__ optimisation__LITBR__v.1.1.1, Apr 2008__LITBR__ bug fix : if string2 was in string1, result would be erroneous__LITBR__v.1.1, Feb 2008__LITBR__ returns empty if searchString1 is not found__LITBR__v.1, Mar 2007__LITBR____LITBR__extracts the middle of a text in between delimiters, based on a search strings and an occurrence numbers__LITBR__occurrences can be positive (starting from the beginning of the text) or negative (starting from the end)__LITBR__The second string will be found only after the first one.__LITBR__Both string can be included or excluded with boolean parameters.__LITBR____LITBR__e.g : BetweenNext ( "A 1234567890 X B 1234567890 X C 1234567890 X" ; "B" ; 1 ; 1 ; "X" ; 1 ; 0 )__LITBR__= "B 1234567890 "__LITBR____LITBR__see also Between, Before and After functions__LITBR__*/__LITBR__Let ([__LITBR__ _occurrence1 = Case ( _occurrence1 = 0 ; 1 ; _occurrence1 )__LITBR__; _occurrence2 = Case ( _occurrence2 = 0 ; 1 ; _occurrence2 )__LITBR__; _lenStr1 = Length ( _searchString1 )__LITBR__; _p1= Position ( _text ; _searchString1 ; Case ( _occurrence1 < 0 ; Length ( _text ) ; 1 ) ; _occurrence1 )__LITBR__; _rightText = Replace ( _text ; 1 ; _p1 + _lenStr1 - 1 ; "" )__LITBR__; _p2= Position ( _rightText ; _searchString2 ; Case ( _occurrence2 < 0 ; Length ( _rightText ) ; 1 ) ; _occurrence2 )__LITBR__; _content = Left ( _rightText ; _p2 - 1 )__LITBR____LITBR__]__LITBR__;__LITBR__Case ( _p1 and _p2__LITBR__ ; Case ( _include1_boolean ; _searchString1 ) & _content & Case ( _include2_boolean ; _searchString2 )__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/87__LITBR____LITBR__ Prototype: BetweenNext( _text; _searchString1; _occurrence1; _include1_boolean; _searchString2; _occurrence2; _include2_boolean )__LITBR__ Function Author: Fabrice (http://www.fmfunctions.com/mid/37)__LITBR__ Last updated: 02 December 2010__LITBR__ Version: 2.2__LITBR____LITBR__*/__LITBR__// ===================================
Login or register to comment
Create a new account with fmcustomfunctions.com or login to post a comment.
Comments
29 November 2008
(Edited by Genx on 30/11/08 )
29 November 2008
01 December 2010
Reason being: when parsing html, you normally don't care about attributes on the tags you're searching for.
E.g.
A search for:
<body*>
would return the occurrence
<body topmargin="5" leftmargin="5">
Etc.
02 December 2010
I wrote a custom html parsing function instead: http://www.fmfunctions.com/fid/284
02 December 2010
Something like :
BetweenNetxt ( BetweenNext ( $html ; "<body" ; n ; 1 ; "</body>" ; 1 ; 1 ) ; ">" ; 1 ; 0 ; "</body>" ; 1 ; 0 )
(not tested)
(Edited by Fabrice on 02/12/10 )