Brian Dunning's FileMaker Custom Functions

ExtractPortion ( textField ; prePortion ; postPortion )

Extract a portion of a text field

  Average rating: 4.0 (38 votes) Log in to vote

Doug Elam   Doug Elam
US Home Systems, Inc.
http://www.ushomesystems.com/

Share on Facebook Share on Twitter

  Sample input:
ExtractPortion ( "http://www.MyHappyPlace.com" ; "www." ; ".com" )
  Sample output:
MyHappyPlace

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

The "middle" function is nice, but it requires you to know how many characters you want to extract. Sometimes, you don't know this, so you have to make complicated calculations to extract data. This is a simple function to extract data between point A and point B.

 

Comments

Daniel Wood   Daniel Wood, Digital Fusion Ltd
Sep 22, 2010
Note that this extracts the contents between the first occurrences of prePortion & postPortion in the text.
 
Mike Beargie   Mike Beargie, MainSpring, Inc.
Sep 30, 2017
This function actually fails in instances where the first occurrence of the postPortion is before the first occurrence of the prePortion.

EG:
<div class='test'>some content</div>
<div class='test2'>some content</div>

If I run:
ExtractPortion ( thatfield ; "<div class='test2'>" ; "</div>" )

it will fail due to the first "</div>" occurrence.

You can correct this in changing:
end = Position ( text ; postPortion ; 1 ; 1 ) - 1 ;

to this:
end = Position ( text ; postPortion ; start ; 1 ) - 1 ;
 

Log in to post comments.

 

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

Under construction. Email me your wish list for improvements.