Join The Works program to have access to the most current content, and to be able to ask questions and get answers from Revelation staff and the Revelation community

At 14 JAN 2013 12:59:51AM John Grant wrote:

I am working in OI v 9.3.2

I want to import a tab-delimited text file into a database. In one of the tab separated fields, there are several imbeded phrases within parentheses - like "this is an example (based on future studies) of a basic (although complex) theory."

I want to extract the phrase and construct two separate phrases: "this is an example of a basic theory" as one and "(based on future studies) (although complex)" in another.

In other words, I need to generate two phrases separated by @vm

How can I do this with OI code?


At 14 JAN 2013 04:29AM Carl Pates wrote:

John,

String parsing is usually done by judicious use of the "[]" and Col2() operators - here's a longer, but more obvious way:

      str = "this is an example (based on future studies) of a basic (although complex) theory."

      pos = 1

      p1  = ""

      p2  = ""

   

      loop

         ch = str[pos,1]

         pos += 1

      while len( ch )

         * // If we find a opening parentheses then scan forward and extract 

         * // until we get to the end one

         if ( ch == "(" ) then

            p2 :=  ch : str[pos,")"] : ")"

            pos = col2() + 1

         end else

            * // Simply concatenate the character. watching out for extra

            * // spaces...

            if ( ch = " " ) then

               if ( p1[-1,1] = " " )  else

                  p1 := ch

               end 

            end else            

               p1 := ch

            end

         end

      repeat



      retVal = p1 : @vm : p2

But the "p1" concatenation slows things down, so here's a faster version:

      str = "this is an example (based on future studies) of a basic (although complex) theory."

      pos = 1

      p1 = ""

      p2 = ""

      

      eof = len( str )

      loop

         p1 := str[pos,"("]

         pos = col2()+1

      until ( pos > eof )

         p2 := "(" : str[pos,")"] : ")"

         pos = col2() + 1

      until ( pos > eof )

      repeat

      

      * // remove extra spaces

      p1 = trim( p1 )



      retVal = p1 : @vm : p2

Disclaimer - I haven't tested this code in any meaningful way but it should give you an idea…

Carl Pates

Sprezzatura

The Sprezzatura Blog

World leaders in all things RevSoft


At 14 JAN 2013 08:34AM John Grant wrote:

I used your second suggestion and it worked great! I saw no glitches.

Thanks

John

View this thread on the Works forum...

  • third_party_content/community/commentary/forums_works/70ecdf554e95dfefec1f0e764.txt
  • Last modified: 2024/01/04 20:57
  • by 127.0.0.1