string manipulation (OpenInsight 32-bit)
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 : p2But 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 : p2Disclaimer - I haven't tested this code in any meaningful way but it should give you an idea…
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