I got interested in the various approaches and put together a speed
comparison using several of the approaches suggested in the discussion.
The code should run as written if you have REGEXP.FLL available in your
system. The results are the same except for the UseLines approach where
a space gets dropped at the end of some of the lines. Take a guess about
which one will run the fastest before you run it. - Joe Yoder
SET LIBRARY TO regexp.fll ADDITIVE
* KillBrac
m.tstart = SECONDS()
FOR m.x = 1 TO 100000
m.result = KillBrac("Apples [some text]; oranges [some more text];
bananas [more text];")
ENDFOR
?'>| ' + m.result + '|< 100,000 in ' + TRANSFORM(SECONDS() - m.Tstart) +
' seconds (KillBrac)'
* Regular
m.tstart = SECONDS()
FOR m.x = 1 TO 100000
m.result = Regular("Apples [some text]; oranges [some more text];
bananas [more text];")
ENDFOR
?'>| ' + m.result + '|< 100,000 in ' + TRANSFORM(SECONDS() - m.Tstart) +
' seconds (Regular)'
* UseLines
m.tstart = SECONDS()
FOR m.x = 1 TO 100000
m.result = UseLines ("Apples [some text]; oranges [some more text];
bananas [more text];")
ENDFOR
?'>| ' + m.result + '|< 100,000 in ' + TRANSFORM(SECONDS() - m.Tstart) +
' seconds (UseLines)'
* Extract
m.tstart = SECONDS()
FOR m.x = 1 TO 100000
m.result = Extract ("Apples [some text]; oranges [some more text];
bananas [more text];")
ENDFOR
?'>| ' + m.result + '|< 100,000 in ' + TRANSFORM(SECONDS() - m.Tstart) +
' seconds (Extract)'
return
* My approach
Function KillBrac
parameter m.instr
local m.B, m.E
m.B = at('[', m.instr)
m.E = at(']', m.instr)
do while m.B > 0 and m.E > 0
m.instr = left(m.instr, m.B -1) + subst(m.instr, m.E + 1)
m.B = at('[', m.instr)
m.E = at(']', m.instr)
enddo
return m.instr
* Suggested by Richard Kaye (expression by Ed Leafe)
function Regular
PARAMETERS m.instr
RETURN RegExp(m.instr,"(\[[^\]]+\])",1,"")
*Suggested by Alan Bourke
FUNCTION UseLines
PARAMETERS m.lcin
Local m.retval, m.lText, m.iicount
m.Retval = ""
m.lText = strtran(m.lcIn, "[", chr(13) + chr(10) + "[")
m.lText = strtran(m.lText, "]", "]" + chr(13) + chr(10))
For m.iicount = 1 to memlines(m.lText)
if left(mline(m.lText, m.iicount), 1) <> "["
m.retval = m.retval + mline(m.lText, m.iicount)
endif
Next m.iicount
Return m.retval
* Suggested by Kam
FUNCTION Extract
PARAMETERS m.instr
local m.jnk
DO WHILE '['$ m.instr AND AT(']', m.instr) > AT('[', m.instr)
m.jnk = STREXTRACT(m.instr, '[', ']')
m.instr = STUFF(m.instr, AT(m.jnk, m.instr) - 1, LEN(m.jnk) + 2,'')
ENDDO
RETURN m.instr
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.