Efficient Way To Check If Certain Characters Exist in Variable
warrenkuhl at gmail.com
Wed Jan 19 13:50:01 EST 2011
Thanks for the suggestions! I will use the replacetext and compare the
speed with the loop and see which is quicker.
On Wed, Jan 19, 2011 at 12:40 PM, Jeff Massung <massung at gmail.com> wrote:
> On Wed, Jan 19, 2011 at 11:34 AM, Warren Kuhl <warrenkuhl at gmail.com>
> > What would be the most efficient way to check a variable and replace any
> > the characters with empty if the character is not a alpha (upper or
> > numeric (0-9) or a '-'?
> > The only way I can think of doing this is a repeat loop and checking the
> > value of each character and replacing with empty if not alpha, numeric or
> > '-'.
> > Any other suggestions for more efficient code?
> Well, it depends on what your definition of "efficient" is. If you want a
> put replaceText(tSource, "[^A-Za-z0-9\-]+", empty) into tDest
> That's using regular expression. But that might be a lot less performance
> (speed-wise) than doing it yourself in a loop:
> repeat for each char c in tSource
> if c is in "abcdef...WXYZ0123456789-" then
> put c after tDest
> end if
> end repeat
> Jeff M.
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
More information about the Use-livecode