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

Document created by David Moyer on Aug 3, 2016Last modified by David Moyer on Aug 10, 2016
Version 5Show Document
  • View in full screen mode

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

 

Example Input $myText:

name=Bart

address=742 Evergreen Ter

city=Springfield

state=OR

 

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:

Let(

  [

    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);

    ""

  )

)

 

Capture.PNG

 

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

 

EDIT:

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

Attachments

    Outcomes