Brian Dunning's FileMaker Custom Functions

split ( string ; occurrence ; character )

Splits a string based on a character and returns the nth value

  Average rating: 3.9 (41 votes) Log in to vote

David Snyder   David Snyder
david at biosearchtech dot com
david at biosearchtech dot com

Share on Facebook Share on Twitter

  Sample input:
split( "Effortlessly|Manage|Your|Information", 2, "|")
  Sample output:
Manage

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

This function will split up a string based on a character you specify and then return one of the values. Its a simple but useful way to get multiple parameters using FMP7's Get( ScriptParameter ) script step. Just call a script using "parameter1|parameter2|parameter n" and use this function to get the value you want.

 

Comments

Bryan Dam   Bryan Dam, Location Unknown
Aug 22, 2012
This function, as written doesn't prooperly handle an occurrance that is greater than the number of actual occurrances in the string. Where it should return nothing it returns multiple values.

Let( [

startPos = Position ( string ; character ; 1 ; occurrence - 1 );
endPos = Position ( string ; character ; 1 ; occurrence );
argLen = endPos - startPos;
count = PatternCount ( string ; character )

];

Case (
occurrence ≤ count ; Middle ( string ; startPos + 1 ; argLen - 1 ) ;
occurrence = count + 1 ; Middle( string ; startPos + 1; Length ( string ) - startPos );
""
)

)
 
Alex Taylor   Alex Taylor, Vancouver, BC
May 17, 2013
Here's a slightly updated function that takes multiple-length characters into account (I wrote this to be able to split on " OR " in search queries.

Returns the occurence without the search characters.

One situation this doesn't account for, though, is if your character occurs at the very start of the string (" OR search term").

Let( [

charLen = Length ( character );
startPos = Position ( string ; character ; 1 ; occurrence - 1 );
endPos = Position ( string ; character ; 1 ; occurrence );
argLen = endPos - startPos;
count = PatternCount ( string ; character )

];

Case (
occurrence = 1 ; Middle ( string ; startPos ; argLen - 1 ) ;
occurrence ≤ count ; Middle ( string ; startPos + charLen ; argLen - charLen ) ;
occurrence = count + 1 ; Middle( string ; startPos + charLen; Length ( string ) - startPos );
""
)

)
 

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.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: