On Wed, Jan 19, 2011 at 11:34 AM, Warren Kuhl <[email protected]> wrote:
> What would be the most efficient way to check a variable and replace any of
> the characters with empty if the character is not a alpha (upper or lower),
> 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
1-liner:
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
HTH,
Jeff M.
_______________________________________________
use-livecode mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode