Brian Dunning's FileMaker Custom Functions

CamelBreaker ( string ; start ; broken )

Breaks up a camel case string into words.

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

bigtom   bigtom - Show more from this author

Share on Facebook Share on Twitter

  Sample input:
CamelBreaker ( "brokenCamelCase"; 1; "" )
  Sample output:
Broken Camel Case

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

Breaks up a camel case string into words by evaluating each characters ASCII and concatenates a new string with spaces as needed.

 

Comments

Joshua Willing   Joshua Willing, Willing Apps
Jul 22, 2018
Cool function!

Not that a camel case string would ever be 50k characters, but this can be handled without recursion too:

Trim (
Substitute ( string ;
[ "A" ; " A" ] ;
[ "B" ; " B" ] ;
[ "C" ; " C" ] ;
[ "D" ; " D" ] ;
[ "E" ; " E" ] ;
[ "F" ; " F" ] ;
[ "G" ; " G" ] ;
[ "H" ; " H" ] ;
[ "I" ; " I" ] ;
[ "J" ; " J" ] ;
[ "K" ; " K" ] ;
[ "L" ; " L" ] ;
[ "M" ; " M" ] ;
[ "N" ; " N" ] ;
[ "O" ; " O" ] ;
[ "P" ; " P" ] ;
[ "Q" ; " Q" ] ;
[ "R" ; " R" ] ;
[ "S" ; " S" ] ;
[ "T" ; " T" ] ;
[ "U" ; " U" ] ;
[ "V" ; " V" ] ;
[ "W" ; " W" ] ;
[ "X" ; " X" ] ;
[ "Y" ; " Y" ] ;
[ "Z" ; " Z" ]
)
)
 
Jonathan Fletcher   Jonathan Fletcher, Fletcher Data Consulting
Aug 19, 2018
Just in case there might be a stray space in the text, I would likely add [ " " ; " " ] as the last substitution to catch them.
 
Jonathan Fletcher   Jonathan Fletcher, Fletcher Data Consulting
Aug 19, 2018
Oops, that was meant for Joshua.
 
Jonathan Fletcher   Jonathan Fletcher, Fletcher Data Consulting
Aug 19, 2018
Like the recursive one better, though.
 
Joshua Willing   Joshua Willing, Willing Apps
Sep 19, 2018
@Jonathan fletcher why is recursion better? Just curious.
 
Howard Schlossberg   Howard Schlossberg, FM Professional Solutions
Sep 10, 2021
I liked Tom's recursive version, but I made some modifications I thought might be useful for others. Since my use case is converting a CamelCase file name, I wanted to handle some inconsistencies (i.e. someone DID put a space in the file name, or a dash as in "X-MenMovie", or a number as in "X-MenMovie10"). Building off Tom's, my result is:

Let (
[
// string= the sting you want to break
// start= the starting position in the string
// broken = the broken string. Pass in empty string "" in most cases

leng = Length ( string );
p = start;
c = Middle ( string ; p ; 1 );
dec = Code ( c );
prevD = Code( Right( broken; 1 ) );
nextD = Code( Middle( string; p+1; 1 ));
broken = broken & Case (
prevD=32 or prevD=45; ""; /*NO space if there's already a space or a dash*/
dec >= 65 and dec <= 90 and nextD >= 97 and nextD <= 122; " "; /*uppercase followed by lowercase*/
dec >= 65 and dec <= 90 and not( prevD >= 65 and prevD <= 90 ); " " ; /*uppercase not following another uppercase*/
dec >= 48 and dec <= 57 and prevD >= 97 and prevD <=122; " " /*number following lowercase*/
) & c

];
Case ( p = leng; Trim ( broken ); CamelBreaker ( string; p +1; broken ) )
)

Hope that helps someone!
 

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: