On Sunday, September 28, 2003, at 09:55 AM, Mark Brownell wrote:


There is probably a regEx way but I have found that this tends to be faster in most speed tests.

I believe you it's faster in this case, but regex is usually faster than one might think. It is after all calling an optimized C library to do all the work :-)


Here are two trim whitespace functions that had written. To my surprise the regex variant is way, way faster!

--
-- regex method
--
function trim pText
  get replaceText(pText, "^\s+", empty)
  return replaceText(it, "\s+$", empty)
end trim

--
-- non regex method --
local lWhitespaceChars


on startup
 -- prepare list of characters to be used by trim()
 -- CRLF = ascii 13+10
 put tab & space & CRLF into lWhitespaceChars
end startup

function trim pText
  repeat while char 1 of pText is in lWhitespaceChars
    delete char 1 of pText
  end repeat
  repeat while char -1 of pText is in lWhitespaceChars
    delete char -1 of pText
  end repeat
  return pText
end trim


Alex Rice <[EMAIL PROTECTED]> | Mindlube Software | http://mindlube.com


what a waste of thumbs that are opposable
to make machines that are disposable  -Ani DiFranco

_______________________________________________
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to