Simple Text Parsing Custom Function (good for name/value pairs, xml)

Version 5

    This is called "simple" because it has obvious limitations*.  But it can be real handy too.


    Example Input $myText:


    address=742 Evergreen Ter




    Usage examples:


    ParseValueByBookends ( $myText; "city="; "¶") will yield "Springfield"

    ParseValueByBookends ( $Correspondence; "My name is "; ".") will yield "Mud", given the writer, Mud, used that sentence form

    ParseValueByBookends ( $GettysburgAddress; "The world will little note,"; ",") will yield " nor long remember what we say here"

    ParseValueByBookends ( $myXML; "<Response>"; "</Response>") will yield the text response message embedded in $myXML, assuming it contains one


    The function:



        posL = Position(text; leftSideTag; 1; 1);

        posR = Position(text; rightSideTag; posL + 1; 1);

        leftStart = posL + Length(leftSideTag)


      If(posL > 0 and posR > posL;

        Middle(text; leftStart; posR - leftStart);







    * - The main limitation is that it simply returns the first occurrence of the value indicated by the tags.



    PosR = ... PosL + 1, takes care of duplicate tags.