Patternize ( )

Function stats

Average user rating
5.0000
148
368
9999
Support
FileMaker 7.0 +
Date posted
26 July 2014
Version
1
Recursive function
Yes

Author Info
 Steve Allen

15 functions

Average Rating 5.0

author_avatar



 

Function overview

Prototype

Patternize  ( direction;   pattern;   replaceChar;   value;   pad? )


Parameters

direction  String saying which end to start on. RTL = Work from the right to the left. Anything else = work from the left to the right.


pattern  String pattern into which the value characters will be replaced


replaceChar  String of character(s) which will be replaced in the pattern by characters from the value


value  String which will be replaced into the pattern


pad?  Boolean ; False = Stop when you run out of pattern or value ; True = put leftovers on the end when complete -- i.e. stop when you run out of both


Description

Tags:  sprintf   pattern   mask   format  

Very versatile function. Takes any string of characters as pattern, as placeholders (replaceChar), or as value.

pad? lets you tell it whether to stop when it runs out of either-pattern-or-value, or when it runs out of both only. The effect of setting this to True is that if your pattern is longer than your value (or vice versa) it tacks the leftover onto whichever end it finishes on (left if you're working from the right; right if from the left).

Examples

Sample input

Patternize ( "RTL" ; "xxxx-xxxx-xxxx-####" ; "#" ; 5105105105105100 ; 0 )

Patternize ( "LTR" ; "(###) ###-#### x. #####" ; "#" ; Filter ( "707 422 4053x123" ; "0123456789" ); 0 )

Patternize ( "RTL" ; "000xx" ; "x" ; 20 ; 1 )

Patternize ( "LTR" ; "%#xxx;" ; "#x" ; Char ( 125 ) & "AD012" ; 1 )


Sample output

xxxx-xxxx-xxxx-5100

(707) 422-4053 x. 123

00020

%}AD0;12

 

Function code

Let ([
    rtl        = Lower ( direction ) = "rtl"
;    prl        = Length ( pattern ) - 1
;    patternChar    = Middle ( pattern ; 1 + prl*rtl; 1 )
;    patternRemains    = Middle ( pattern ; 2-1*rtl ; prl )

;    useValueChar    = not IsEmpty ( Filter ( replaceChar ; patternChar ) )
;    vrl        = Length ( value ) - useValueChar
;    valueChar    = Middle ( value ; 1 + vrl*rtl ; 1 )
;    valueRemains    = Middle ( value ; 1+1*useValueChar-1*rtl ; vrl )

;    thisChar        = Case (
                useValueChar
            ;        valueChar
            ;    patternChar
            )
];
    Case ( not rtl ; thisChar ) &
        Case (
            prl and vrl
        ;        Patternize (
                    direction
                ;    patternRemains
                ;    replaceChar
                ;    valueRemains
                ;    pad?
                )
        ;    vrl and pad?
        ;        valueRemains
        ;    prl and pad?
        ;        patternRemains
        )
    & Case ( rtl ; thisChar )
)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/368

    Prototype: Patternize( direction; pattern; replaceChar; value; pad? )
    Function Author: Steve Allen (http://www.fmfunctions.com/mid/148)
    Last updated: 26 July 2014
    Version: 1

*/
// ===================================

 

 

 

 

 

 

 

Top Tags

Text Parsing  (33)
List  (32)
Date  (28)
XML  (26)
Format  (23)
Sql  (22)
Dev  (20)
Debug  (17)
Layout  (15)
Interface  (15)
Text  (14)
Variables  (12)
Filter  (11)
Layout Objects  (11)
Design  (10)
Array  (8)