1 Reply Latest reply on May 13, 2011 4:12 AM by LaRetta_1

    Copying text between two text strings

    happyez

      Title

      Copying text between two text strings

      Post

      Hello everyone

      Dipping in and finally contributing to the forum I have been lurking around in for some time. At least asking questions...

      I want to be able to automatically find a specific string of text (eg "h4" from source code, or "Business Name" from a directory), find the end point (eg "/h4" from source code, or "Location" from a directory), and cut out/copy/set var any text inbetween.

      This means I will be able, through loads of source code text, find the lines I need, and then paste them into other fields.

      This really doesn't sound too difficult - but I cannot find any info on the net or these forums. I tried a Brian Dunning one, but that went nowhere for me. And I tried...

      So I thought I'd ask anyone here.

      This is how I thought it could happen. I would go:

      1) go to  the <Data> field where the full set of text is kept.

      2) Replace/Find for eg 'h4" within <Data>.

      3) In a calc field, ask the end point to be "/h4". Now I have the bookends. I would program these two into the calc field myself.

      4) Copy/Set Var whatever is between these "h4"'s, and Set Field into a new field, called, say, <between> ...

      Possibly an easier way would be to find eg <h5> text and just ask it to copy 100 characters ahead, but that could become messy, and some lines may be cut short.

      Would love someone's help in this problem. It seems SO easy in theory, but a bugger to do for me in practice...

        • 1. Re: Copying text between two text strings
          LaRetta_1

          Try this ... create a global text field called From and a global text field called To.  This will hold your beginning and ending phrases or words.  Then create a calculation ( result is text) with:

          Let (  [
          start = Position ( Data ; From ; 1 ; 1 ) ;
          end = Position ( Data ; To ; 1 ; 1 ) + Length ( To ) + 1
          ] ;
          Middle ( Data ; start ; end - start )
          )

          You can then set the calculation on your layout as well next to the two globals (label the calc 'copy contents' so User knows and set field behavior (data tab) as 'select entire contents upon entry.'  When you click into the field, it will insert the contents onto your clipboard.  highlight the entire result so you can copy it onto your clipboard.  If you wish you can turn off entry to the field and attach script so that clicking the field automatically copies to clipboard (script-step Copy) or even use script trigger.