Software Venture Consulting

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
Training
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages
Videos
Adventures
Links

Shopping Cart
Shopping Cart

Search:

Free Newsletter
Signup


Contact


Privacy Policy



FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

 

 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

BetweenNext ( _text ; _searchString1 ; _occurrence1 ; _include1_boolean ; _searchString2 ; _occurrence2 ; _include2_boolean )_

Rate this function:  

RatingRatingRatingRatingRating
  Average rating: 4.3  (38 votes)
  Discuss this Custom Function

Fabrice Nordmann, 1-more-thing
http://www.1-more-thing.com

extracts the middle of a text in between delimiters, based on search strings and an occurrence numbers

Sample Input:
BetweenNext ( "A 1234567890 X B 1234567890 X C 1234567890 X" ; "B" ; 1 ; 1 ; "X" ; 1 ; 0 )
Sample Output:
"B 1234567890 "


 Then copy & paste into FileMaker Advanced's Edit Custom Function window.

Click here to copy To Clip Manager if you have myFMbutler's Clip Manager installed

Description:

/*
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 )
)
)

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

This is my Custom Function and I want to edit it

Discuss:

5 most recent comments | Show all 8 comments

BetweenPrevious is included in the "Pro" pack available on our web store (no, just kidding ;))
Please feel free to modify this function and share it!
Fabrice Nordmann

Fabrice, Brussels
January 24, 2012 2:43am

This function works (nearly) perfectly for parsing out values from a web result like this:
field1=value1&field2=value2&field3=value3

The only problem is that when I plug in "field3=" for _searchString1 and "&" for _searchString2, I get a blank result (because there is no "&" character to look for on the tail end).

I modified the custom function to include this bit in the Let() statement:

Let ([
_text = _text & If(Right(_text; 1) ≠ _searchString2; _searchString2; "")
; _occurrence1 = Case ( _occurrence1 = 0 ; 1 ; _occurrence1 )

Would this be a good addition to your custom function, Fabrice? Or would it mess up in some cases?

HazMatt, Blaine, MN, USA
January 22, 2013 11:10am

This custom function is a masterpiece!

Katy Butterworth, New Zealand
September 22, 2013 5:40pm

Thank you Katty.
Matt, I didn't see your post, sorry.
I like a function not to do hidden stuff, otherwise it becomes more difficult to use in certain situations, although it's easier in some others.
In your situation I would rather send a different parameter such as [your string] & "&".
By the way something is broken in 12 with the Position function. You should change the constant 1 with 0 so this function and others keep working in all scenarios
An updated version can be found on fmfunctions.com

Fabrice Nordmann, Brussels
September 22, 2013 11:58pm

Next to the bulit-in functions in FileMaker, this function is the one I use most in my document assembly scripts. It is indispensable! I added two lines (suffixed with "added") to your code to return the searchstrings as they appear in the text. It aids in using the Substitute function. Thank you.

; _p1= Position ( _text ; _searchString1 ; Case ( _occurrence1 < 0 ; Length ( _text ) ; 1 ) ; _occurrence1 )
; _searchString1 = If ( _p1 ; Middle ( _text ; _p1 ; _lenStr1 ) ; _searchString1 ) //Added.
; _rightText = Replace ( _text ; 1 ; _p1 + _lenStr1 - 1 ; "" )
; _p2= Position ( _rightText ; _searchString2 ; Case ( _occurrence2 < 0 ; Length ( _rightText ) ; 1 ) ; _occurrence2 )
; _searchString2 = If ( _p2 ; Middle ( _rightText ; _p2 ; Length ( _searchString2 ) ) ; _searchString2 ) //Added.

Lewis Lorenz, Tulsa
September 15, 2017 7:52am

Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Your Name:
City/Location:
Comment:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 2 + 6 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. ProperAllWords ( text )
  (Thu, Dec 14, 5:19pm)
2. MatchExist ( SourceTable.Field ; DestTable.Field ; ReturnField )
  (Thu, Dec 14, 1:07pm)
3. BVR_Format ( bvr )
  (Wed, Dec 13, 5:32pm)
4. NumberToHexadecimal(NumberValue)
  (Fri, Dec 08, 8:54am)
5. Get_BaseTable
  (Thu, Dec 07, 4:27pm)
6. JSONCreateVarsFromKeys ( json ; namespace )
  (Wed, Dec 06, 8:21pm)
7. GetTableNzme ( field )
  (Tue, Dec 05, 9:16pm)
8. TimeFormatAsText ( theTime )
  (Mon, Nov 13, 1:59pm)

RSS Feed of Custom Functions