BetweenNext ( )

Function stats

Average user rating
4.0000
37
87
9999
Support
FileMaker 7.0 +
Date posted
28 November 2008
Last updated
02 December 2010
Version
Recursive function
No

Author Info
 Fabrice

74 functions

Average Rating 4.4

author_avatar



 

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

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

 

Comments

Genx
29 November 2008



Fabrice, in your example, if you're including the first character shouldn't it actually be included in the string?
(Edited by Genx on 30/11/08 )
  General comment
Genx
29 November 2008



Nevermind, I thought your first character was X not B. My bad :(
  General comment
Genx
01 December 2010



Function is great... Wild cards would be really nice to have in the search strings though - particularly just the 0 or more character wild card: *

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.
     Feature request
Genx
02 December 2010



Again nevermind lol. Realized this function probably has a different purpose.

I wrote a custom html parsing function instead: http://www.fmfunctions.com/fid/284
  General comment
Fabrice
02 December 2010



Hi Alex, I guess you could still use this function for that.
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 )
  General comment