Brian Dunning's FileMaker Custom Functions

balance ( theText ; openbracket ; closebracket ; instance )

Get text to length that balances open/close markers

  Average rating: 4.4 (42 votes) Log in to vote

Bruce Robertson   Bruce Robertson

Share on Facebook Share on Twitter

  Sample input:
balance( "((a=b); (1); [ (a,b);(c;d)]); ( 1;3;4)"; "("; ")";1)
  Sample output:
((a=b); (1); [ (a,b);(c;d)])

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

Given text such as JSON or HTML or XML formatted text, look for specified instance of openbracket, then look for instance of closebracket satisfying condition that count of openbracket = count of closebracket.

Returns all text up to and including identified closebracket

Can be used with single or multi character values:
{}; (); []; ; <: :> etc.

Recursive function.
Edited 12/17/2014

 

Comments

Christopher Kuhn   Christopher Kuhn, Temecula
Jul 11, 2014
Hi,
I found that if the openbracket and closebracket are the same character then the function returns a single character...the bracket.

I changed the function such that the location of the close bracket is AFTER the location of the openbracket....

original: p2 = Position ( theText; closebracket ; 1; $instance ) ;
change: p2 = Position ( theText; closebracket ; p1+1 ; $instance ) ;

Now, i can find quoted strings with the function :)
 
Bruce Robertson   Bruce Robertson
Dec 17, 2014
Christopher - thanks for the suggested mod! Incorporated in revised version.
 

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.