BetweenOpenCloseTag ( )

Function stats

Average user rating
46
381
9999
Support
FileMaker 8.0 +
Date posted
06 May 2015
Last updated
08 May 2015
Version
Recursive function
No

Author Info
 Agnès

17 functions

Average Rating 4.6

author_avatar



 

Function overview

Prototype

BetweenOpenCloseTag  ( Txt;   OpenTag;   CloseTag;   n )


Parameters

Txt  Text for extract


OpenTag  Extract after open tag


CloseTag  Extract before close Tag


n  Target Occurrence


Description

Tags:  xml    Text Parsing   list   extract   between  

BetweenOpenCloseTag ( Txt ; OpenTag ; CloseTag ; n ) v1_5

** 050715 - Suppress +1 variable Pos ( thanks Menno ! )

//
// to extract between 2 tags even if the tag is repeated and nested
// the closing tag matches the opening tag
// BetweenOpenCloseTag is not recursive function
/*
//---------------------------------- Parameter
• Txt : Text for extract
• OpenTag : Extract after open tag
• CloseTag : Extract before close Tag
• n : Target Occurrence
//---------------------------------- Example
With Txt =
"<dict>¶
        <dict>¶
            <key>Compositeur</key>¶
        <dict>¶
            <key>Acteur</key>¶
            <dict>¶
            <string>Ok</string>¶
            </dict>¶
            <key>role</key>¶
        </dict>¶
        <string>Test_Ok</string>¶
        </dict>¶
        <string>Test</string>¶
</dict>¶
    <dict>¶
        <close>¶
            <dict>¶
                <key>bonus</key>¶
            <array>¶
            <dict>¶
                <key>editeur</key>¶
            </dict>¶
            </array>¶
            <string>Actrice</string>¶
            </dict>¶
        <Oui>et</Oui>¶
        <string>Joueur</string>¶
        </close>¶
    </dict>¶
( et ceci ( was ok ( également ) with des ) parenthèses [ ou des crochets ] )"

- BetweenOpenCloseTag ( Txt ; "<dict>"; "</dict>"; 3 )
> Result :
"            <key>Acteur</key>
            <dict>
            <string>Ok</string>
            </dict>
            <key>role</key>"
        
- BetweenOpenCloseTag ( Txt ; "("; ")"; 2 )
> Result : "was ok ( également ) with des"
*/
//————————--—---------------------——————-————
// @ Agnès - May 2015- BugReport
// Substitute ( filemaker§tictac.fr ; § ; @ )
//—————---------------------———————-———-————-

Examples

Sample input

BetweenOpenCloseTag ( "<dict>¶
<dict><key>Compositeur</key>¶
<dict>¶
<key>Acteur</key>¶
<dict><string>Ok</string>
</dict>¶
<key>role</key>¶
</dict>¶
<string>Test_Ok</string>¶
</dict>¶
<string>Test</string>¶
</dict>" ;
"<dict>"; "</dict>"; 3 )


Sample output

" <key>Acteur</key>
<dict>
<string>Ok</string>
</dict>
<key>role</key>"

 

Function code

BetweenOpenCloseTag ( Txt ; OpenTag ; CloseTag ; n ) v1_5
//
// to extract between 2 tags even if the tag is repeated and nested
// the closing tag matches the opening tag
// BetweenOpenCloseTag is not recursive function
/*
//---------------------------------- Parameter
• Txt : Text for extract
• OpenTag : Extract after open tag
• CloseTag : Extract before close Tag
• n : Target Occurrence
//---------------------------------- Example
With Txt =
"<dict>¶
        <dict>¶
            <key>Compositeur</key>¶
        <dict>¶
            <key>Acteur</key>¶
            <dict>¶
            <string>Ok</string>¶
            </dict>¶
            <key>role</key>¶
        </dict>¶
        <string>Test_Ok</string>¶
        </dict>¶
        <string>Test</string>¶
</dict>¶
    <dict>¶
        <close>¶
            <dict>¶
                <key>bonus</key>¶
            <array>¶
            <dict>¶
                <key>editeur</key>¶
            </dict>¶
            </array>¶
            <string>Actrice</string>¶
            </dict>¶
        <Oui>et</Oui>¶
        <string>Joueur</string>¶
        </close>¶
    </dict>¶
( et ceci ( was ok ( également ) with des ) parenthèses [ ou des crochets ] )"

- BetweenOpenCloseTag ( Txt ; "<dict>"; "</dict>"; 3 )
> Result :
"            <key>Acteur</key>
            <dict>
            <string>Ok</string>
            </dict>
            <key>role</key>"
        
- BetweenOpenCloseTag ( Txt ; "("; ")"; 2 )
> Result : "was ok ( également ) with des"
*/
//————————--—---------------------——————-————
// @ Agnès - May 2015- BugReport
// Substitute ( filemaker§tictac.fr ; § ; @ )
//—————---------------------———————-———-————-

Let ([

Net = Substitute ( Txt ; [ OpenTag ; ¶ & OpenTag & ¶ ] ; [ CloseTag ; ¶ & CloseTag & ¶ ] ) ;
S = FilterValues ( Net ; OpenTag & ¶ & CloseTag ) ;
P = Position ( S ; OpenTag ; 1 ; n ) ;
Test = Middle ( S ; P ; Length ( OpenTag ) + Length ( CloseTag ) + 1 ) ;
Ex = Case ( PatternCount ( Test ; CloseTag ) ; Test ; Middle ( S ; P ; Position ( S ; CloseTag & ¶ & CloseTag ; P ; 1 ) ) ) ;
Pos = Position ( Txt ; OpenTag ; 1 ; n ) + Length ( OpenTag ) ;
Result = Middle ( Txt ; Pos ; Position ( Txt ; CloseTag ; Pos ; PatternCount ( Ex ; OpenTag ) ) - Pos )
];
Case ( P ; Result ; "Error" )
)

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

    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/381

    Prototype: BetweenOpenCloseTag( Txt; OpenTag; CloseTag; n )
    Function Author: Agnès (http://www.fmfunctions.com/mid/46)
    Last updated: 08 May 2015
    Version: 1.1

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

 

 

 

 

 

 

 

Top Tags

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