PDA

View Full Version : Character Ranges - string.find - string - find


Intrigued
11-07-2005, 07:48 PM
Here is a useful bit of information about Character Ranges (classes are covered as well):

http://lua-users.org/wiki/PatternsTutorial

Here is how you can quickly check for say the number five (5) is between a range of numbers):

-- First define a variable to hold a random number to check against
n = 5

-- Note 'string.find' is all lower-case! It's a LUA function (not AMS created)
result = string.find(n, '[1-8]')

--[[
If there is an instance of '5' between 1 and 8, then show confirmation...
otherwise, show the second (no instances found) dialog. This is a good way
to easily check a "range" of numbers! Forum member Tigger first alerted us
to this LUA innate function. Remember, type 'string.find' in all lower-case...
or the function will not work!
]]
if result then
Dialog.Message("", "Found at least one instance!")
else
Dialog.Message("", "Did not find any instances!")
end